Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

用二分法还是WA,不知怎么搞。

Posted by BlueBlood at 2005-09-15 22:56:22 on Problem 1064
//My code
#include <iostream>
#include <fstream>
#include <cstdio>
#include <string>
#include <cmath>
using namespace std;

int main()
{
	int N, K;
	long TLen = 0;
	float AveLen = 0.0;
	double fOriLen = 0.0;
	long nOriLen = 0;
	int i;


	cin >> N >> K;
	int count = 0;
	long * cable = new long [N];
	long limit = 0;
	
	for (i = 0; i < N; i++)
	{
		cin >> fOriLen;
		
		nOriLen = floor(fOriLen * 100);
		TLen += nOriLen;

		cable[count++] = nOriLen;
	}

	
	limit = ceil( TLen * 1.0 / count);

	long max = 0;
	int index = -1;

	for (i=0; i<N; i++)
	{
		if (cable[i] > max )
		{
			max  = cable[i];
			index = i;
		}
	}

	int tmp = ceil(K *1.0 /N);
	
	if ((max*1.0 / tmp ) < (1.0*limit))
		limit = ceil (max*1.0/tmp);
	do{
		int sum = 0;
		for (i = 0; i < count; i++)
		{
			sum += floor(cable[i]*1.0 / limit);
		}

		if (sum == K)
			break;
		else
			limit --;
	}
	while (1);

	printf("%.2f\n", limit*1.0 / 100);

	return 0;
}
	long TLen = 0;
	float AveLen = 0.0;
	double fOriLen = 0.0;
	long nOriLen = 0;
	int i;


	cin >> N >> K;
	int count = 0;
	long * cable = new long [N];
	long limit = 0;
	
	for (i = 0; i < N; i++)
	{
		cin >> fOriLen;
		
		nOriLen = floor(fOriLen * 100);
		TLen += nOriLen;

		cable[count++] = nOriLen;
	}

	limit = ceil( TLen * 1.0 / count);

	do{
		int sum = 0;
		for (i = 0; i < count; i++)
		{
			sum += floor(cable[i]*1.0 / limit);
		}

		if (sum == K)
			break;
		else
			limit --;
	}
	while (1);

	printf("%.2f\n", limit*1.0 / 100);

	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator