C language problem Pie (half)

Tonight I do autism, and has been a question of WA
gone on the road balding.
I too do mentality. (Sui Suinian Sui Suinian)
topic Link: Pie-1969 HDU
Here Insert Picture Description
generally means that you have N pieces of pie to be divided equally among F friends and myself, to do the most volume.
Here we can use half of it!

When you meet the conditions of the middle value, indicating smaller than its conditions are met, then the lower bound at this time becomes the middle value, when the intermediate value does not satisfy the condition, indicating that it is larger than the conditions are not met, so this time the upper bound becomes an intermediate value.

Since the title is inputted to send the radius, so we need to be converted to a volume (height 1, the area is volume).

So how to determine the intermediate value meets the condition of it? ? ?
Each number is determined to send up to points (area divided by the intermediate value Jipai rounded), then the number of add, compare whether the total number of share at this time may be greater than the number of a friend own (i.e., F + 1), If the value is greater than the intermediate condition is satisfied, change low value, and vice versa.

Note that the PI can be improved by the accuracy in the output. PI = acos (-1).

Kankan then come out of my mind the code

#include<stdio.h>
#include<math.h>
#define PI acos(-1)
#define EPS 1e-6
int main()
{
	int m;
	scanf("%d",&m);
	while(m--)
	{
		int n,i,f,r;
		double s[10000],mid,low=0,high=0;
		scanf("%d %d",&n,&f);
		for(i=0;i<n;i++)
		{
			scanf("%d",&r);
			s[i]=PI*r*r;
			if(high<s[i]) high=s[i];
		}
		while(high-low>=EPS)
		{
			mid=(low+high)/2;
			int sum=0;
			for(i=0;i<n;i++)
			{	
				sum+=(int)(s[i]/mid);
			}
			if(sum>=f+1) low=mid;
			else high=mid;
		}
		printf("%.4f\n",low);
	}
	return 0;
 } 

On such a thing, I WA over many times, because the sum + = (int) (s [i] / mid) At this point, I have not put (int) !!! I do not know why not strengthen the system for the conversion is over no, maybe now my mind is not clear, trained, trained, trained.

Published 22 original articles · won praise 1 · views 1056

Guess you like

Origin blog.csdn.net/Doro_/article/details/104058121