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

化成int后二分,贴份代码

Posted by a280920481 at 2018-12-04 00:17:33 on Problem 1064
#include <iostream>
using namespace std;


int L[10005];


int main()
{
	int N, K, num, lb = 0, rb = 1, mid;
	double c;

	cin >> N >> K;

	for (int i = 0; i < N; i++)
	{
		cin >> c;
		L[i] = (int)(c * 10000 + 0.1);
		if (L[i] > rb)
		{
			rb = L[i];
		}
	}

	while (rb - lb > 1)
	{
		mid = (lb + rb) >> 1;
		num = 0;

		for (int i = 0; (i < N) && (num < K); i++)
		{
			num += (L[i] / mid);
		}

		if (num >= K)
		{
			lb = mid;
		}
		else
		{
			rb = mid;
		}
	}

	lb = (lb + 5) / 100;

	cout << lb / 100 << '.' << (lb % 100) / 10 << lb % 10 << '\n';

	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