题解 | #Dropping tests#

Dropping tests

https://ac.nowcoder.com/acm/problem/51093

思路

01分数规划模板题。

代码

#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
//#define int long long
using namespace std;
const int N=1007;
const int mod=1e9+7;

int n,k;
double a[N],b[N],c[N];

bool check(double ans){
	for(int i=1;i<=n;i++){
		c[i]=a[i]-b[i]*ans;
	}
	sort(c+1,c+1+n);
	double res=0;
	for(int i=n;i>k;i--){
		res+=c[i];
	}
	if(res>=0) return true;
	return false;
} 

signed main(){
	while(cin>>n>>k){
		if(n==0&&k==0) break;
		for(int i=1;i<=n;i++) cin>>a[i];
		for(int i=1;i<=n;i++) cin>>b[i];
		double l=0,r=inf,mid;
		while(r-l>1e-6){
			mid=(l+r)/2;
			if(check(mid)) l=mid;
			else r=mid; 
		}
		cout<<int(l*100+0.5)<<"\n";
	}
	return 0;
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
06-27 15:19
简历上能写3个月吗?
码农索隆:大胆写,主要你能把实习经历包装好,可以看一下我这篇帖子https://www.nowcoder.com/share/jump/4888395581180798063
点赞 评论 收藏
分享
05-29 09:02
门头沟学院 Java
点赞 评论 收藏
分享
评论
1
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务