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

贴个AC代码

Posted by lx865712528 at 2014-08-24 11:59:11 on Problem 2976
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
using namespace std;
typedef __int64 LL;
const int MAXN=1005;
int a[MAXN],b[MAXN];
const double eps=1e-4;
int n,k;
bool check(double val) {
	double ans=0;
	vector<double> tmp;
	for(int i=0;i<n;i++) {
		ans+=(1.0*100*a[i]-1.0*val*b[i]);
		tmp.push_back(1.0*100*a[i]-1.0*val*b[i]);
	}
	sort(tmp.begin(),tmp.end());
	for(int i=0;i<k;i++) ans-=tmp[i];
	return ans>-eps;
}
int main() {
	while(~scanf("%d%d",&n,&k)&&(n||k)) {
		double l=0,r=100,ans=-1;
		for(int i=0;i<n;i++) scanf("%d",&a[i]);
		for(int i=0;i<n;i++) scanf("%d",&b[i]);
		while(r-l>eps) {
			double mid=(l+r)/2;
			if(check(mid)) l=ans=mid;
			else r=mid;
		}
		printf("%.0f\n",ans);
	}
	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