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

cin 超时啊!!

Posted by xiaozhuaixifu at 2013-07-23 22:04:27 on Problem 2976
#include <iostream>
#include <algorithm> 
#include <cstdio>
#include <ctime>
#include <cstdlib>
using namespace std;
const int maxn=1005;
double a[maxn],b[maxn],d[maxn];
const double eps=1e-6;
int n,k;
bool cal(double mid)
{
	for(int i=0;i<n;i++)
		d[i]=a[i]-mid*b[i];
	sort(d,d+n);
	double sum=0;
	for(int i=k;i<n;i++)
		sum+=d[i];
	if(sum>0)return 1;
	else return 0;		
}
int main()
{
	while(scanf("%d%d", &n, &k) != EOF)
	{
		if(n+k==0)break;
		for(int i=0;i<n;i++)
			 scanf("%lf", &a[i]);
		for(int i=0;i<n;i++)
			scanf("%lf", &b[i]); 
		double l=0.0,r=1.0;
		//clock_t t1=clock();
		while(r-l>=eps)
		{
			double mid=(l+r)/2;
			if(cal(mid))l=mid;
			else r=mid;
		}	
		printf("%.0f\n", l * 100);  
		//clock_t t2=clock();
		//cout<<t2-t1<<" ms"<<endl;
	}
	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