poj2976
来源:互联网 发布:ntfs for mac 14 编辑:程序博客网 时间:2024/05/21 02:32
//刚开始想按照每门课的分数除以总分的大小来排序,后来发现不对
//那么思路呢假设我们选了某个物品的集合,那么他们的的应该是集合里面的 总共获得的分数除以总分
//详细的一些东西我会在代码里面解释的;
#include<iostream>#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;double y[1005]; int n,k;struct node{double a;double b;};node ave[1005];bool cmd(double x){int i;for(i=1;i<=n;i++)y[i]=ave[i].a-x*ave[i].b;//这个是文字中的一个变形sort(y+1,y+n+1);double sum=0;for(i=n;i>k;i--){sum+=y[i];}return sum>=0;}int main(){ while(scanf("%d%d",&n,&k)!=EOF,n+k) { int i; for(i=1;i<=n;i++) { scanf("%lf",&ave[i].a); } for(i=1;i<=n;i++) scanf("%lf",&ave[i].b); double str=0; double end=1; for(i=1;i<=100;i++)//看到没有,这里用了二分搜索的办法,复杂度是nlogn { double mid=(str+end)/2; // cout<<mid<<" "; if(cmd(mid)) str=mid; else end=mid; } str*=100; int str1=str; if(str-str1>0.5)//关于题目要求的一个小处理 printf("%d\n",str1+1); else printf("%d\n",str1); }}
0 0
- poj2976
- poj2976
- poj2976
- poj2976
- poj2976
- poj2976
- poj2976
- POJ2976
- [二分]poj2976 Dropping tests
- poj2976 二分最大平均值
- POJ2976--Dropping tests
- POJ2976-Dropping tests
- poj2976 Dropping tests 二分
- [POJ2976] Dropping tests
- POJ2976-Dropping tests
- POJ2976 最大化平均值
- NEERC 2005 Feel Good (Poj2976)
- poj2976 0-1分数规划
- 根据某个层来截图
- linux下PWM程序设计
- 安装Yii2框架
- 配置Tomcat的数据源
- 项目管理PMO相关
- poj2976
- 数据库连接池配置
- MyEclipse2014 如何破解,绝对OK
- Android Dialog
- [物理题+枚举] hdu 4445 Crazy Tank
- 字符串反转
- 仿制任务栏托盘//.net//WCF架构
- tar命令的详细解释
- 归并排序