POJ 2976 Dropping tests(二分答案)
【题目链接】 http://poj.org/problem?id=2976
【题目大意】
给出每门成绩的总分和得分,去除k门成绩之后
使得剩余的成绩分数和除以总分得到的数字最大,要求精度在三位小数之内四舍五入到整数
【题解】
如果答案是x,那么必有选取的几门课程sigma(a*100)>=sigma(b*x)
至于选取,就可以根据a*100-b*x排序,贪心选取即可。
对于最后的精度处理问题,只要将数据放大处理末尾即可。
【代码】
#include <cstdio>
#include <algorithm>
using namespace std;
const int N=1010;
struct data{long long a,b;}p[N];
int n,m,k;
bool cmp(data a,data b){return a.a*1000000-a.b*m>b.a*1000000-b.b*m;}
bool check(int x){
m=x;
sort(p+1,p+n+1,cmp);
long long cnt=0;
for(int i=1;i<=k;i++)cnt+=p[i].a*1000000-p[i].b*x;
return cnt>=0;
}
int main(){
while(~scanf("%d%d",&n,&k),n+k){
k=n-k;
for(int i=1;i<=n;i++)scanf("%lld",&p[i].a);
for(int i=1;i<=n;i++)scanf("%lld",&p[i].b);
int l=0,r=1000000,ans;
while(l<=r){
int mid=(l+r)>>1;
if(check(mid))l=mid+1,ans=mid;
else r=mid-1;
}printf("%d\n",ans/10000+(ans%10000>=5000));
}return 0;
}
POJ 2976 Dropping tests(二分答案)的更多相关文章
- POJ 2976 Dropping tests (二分+贪心)
题意:给定 n 个分数,然后让你去年 m 个分数,使得把剩下的所有的分子和分母都相加的分数最大. 析:这个题并不是分子越大最后结果就越大,也不是整个分数越大,最后结果就越大的,我们可以反过来理解,要去 ...
- POJ 2976 Dropping tests [二分]
1.题意:同poj3111,给出一组N个有价值a,重量b的物品,问去除K个之后,剩下的物品的平均值最大能取到多少? 2.分析:二分平均值,注意是去除K个,也就是选取N-K个 3.代码: # inclu ...
- 二分算法的应用——最大化平均值 POJ 2976 Dropping tests
最大化平均值 有n个物品的重量和价值分别wi 和 vi.从中选出 k 个物品使得 单位重量 的价值最大. 限制条件: <= k <= n <= ^ <= w_i <= v ...
- POJ - 2976 Dropping tests && 0/1 分数规划
POJ - 2976 Dropping tests 你有 \(n\) 次考试成绩, 定义考试平均成绩为 \[\frac{\sum_{i = 1}^{n} a_{i}}{\sum_{i = 1}^{n} ...
- POJ 2976 Dropping tests 【01分数规划+二分】
题目链接:http://poj.org/problem?id=2976 Dropping tests Time Limit: 1000MS Memory Limit: 65536K Total S ...
- POJ 2976 Dropping tests(01分数规划入门)
Dropping tests Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11367 Accepted: 3962 D ...
- POJ 2976 Dropping tests 01分数规划 模板
Dropping tests Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6373 Accepted: 2198 ...
- Poj 2976 Dropping tests(01分数规划 牛顿迭代)
Dropping tests Time Limit: 1000MS Memory Limit: 65536K Description In a certain course, you take n t ...
- POJ 2976 Dropping tests(01分数规划)
Dropping tests Time Limit: 1000MS Memory Limit: 65536K Total Submissions:17069 Accepted: 5925 De ...
- POJ 2976 Dropping tests (0/1分数规划)
Dropping tests Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4654 Accepted: 1587 De ...
随机推荐
- Laravel学习笔记
1.Laravel 5 动态设置缓存引擎 \Config::set('cache.default','redis'); var_dump( \Config::get('cache.default') ...
- Win32 多线程的创建方法和基本使用
Win32多线程的创建方法主要有: (1)CreateThread() (2)_beginthread()&&_beginthreadex() (3)AfxBeginThread() ...
- Light Bulb--zoj3203(三分法)
Light Bulb Time Limit: 1 Second Memory Limit: 32768 KB Compared to wildleopard's wealthiness, h ...
- Listview注意事项
1.缓存 @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder ho ...
- MYSQL 中的变量
1.用户自己定义变量 2.系统变量(全局变量,会话变量) ----------------------------------------------------------------------- ...
- hightchart or hightstock 格式Y数据
hightchart or hightstock 格式Y数据,鼠标放在上面显示两位小数 方法一: tooltip: { shared: true, crosshairs: true , formatt ...
- Intuit Quicken Home & Business 2016(Manage your business and personal finances)
Quicken Home & Business 2016 - Manage your business and personal finances all in one place. Cate ...
- asp.net mvc,做 301 永久重定向
以下代码为 asp.net mvc 4.0 代码做的 301 永久重定向 string url = “http://www.csdn.net/test.html” Response.StatusCod ...
- OpenStack cloudCompute glassary术语project,tenant,user
1,tenantA group of users, used to isolate access to Compute resources(一组用户,用于隔离访问计算资源). An alternati ...
- C++数据结构之最小生成树
最小生成树是图的一部分,一般求最小生成树用Prim算法和Kruskal算法. 对于Prim算法,思想是:在访问过的顶点和未访问的顶点之间选择权值最小的边.Prim算法是基于顶点的操作,适合于顶点较少, ...