题意:给定 n 个分数,然后让你去年 m 个分数,使得把剩下的所有的分子和分母都相加的分数最大。

析:这个题并不是分子越大最后结果就越大,也不是整个分数越大,最后结果就越大的,我们可以反过来理解,要去掉 m 个分数,那么就是要选 n-m个分数,

那么就是 sigma(分子) / sigma(分母) 尽量大,那么最大是多大啊?这个我们可以通过二分来解决,也就是sigma(分子) / sigma(分母) >= x,

因为分子和分母都是正数,所以可以得到 sigma(分子) - sigma(分母)* x  >= 0,也就是 sigma(分子 - x * 分母) >= 0(前n-m项),我们就可以按这个进行排序,

看看前 n-m 项成不成立。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e3 + 10;
const int mod = 1e9 + 7;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
double c; struct Node{
double a, b;
bool operator < (const Node &p) const{
return a - b * c > p.a - p.b * c;
}
};
Node a[maxn]; bool judge(){
sort(a, a + n);
double ans = 0;
for(int i = 0; i < n-m; ++i) ans += a[i].a- a[i].b * c;
return ans >= 0.0;
} double solve(){
double l = 0, r = INF;
for(int i = 0; i < 100; ++i){
c = (l+r) / 2;
if(judge()) l = c;
else r = c;
}
return l;
} int main(){
while(scanf("%d %d", &n, &m) == 2 && n+m){
for(int i = 0; i < n ; ++i) scanf("%lf", &a[i].a);
for(int i = 0; i < n ; ++i) scanf("%lf", &a[i].b);
printf("%.f\n", solve()*100);
}
return 0;
}

POJ 2976 Dropping tests (二分+贪心)的更多相关文章

  1. POJ 2976 Dropping tests [二分]

    1.题意:同poj3111,给出一组N个有价值a,重量b的物品,问去除K个之后,剩下的物品的平均值最大能取到多少? 2.分析:二分平均值,注意是去除K个,也就是选取N-K个 3.代码: # inclu ...

  2. 二分算法的应用——最大化平均值 POJ 2976 Dropping tests

    最大化平均值 有n个物品的重量和价值分别wi 和 vi.从中选出 k 个物品使得 单位重量 的价值最大. 限制条件: <= k <= n <= ^ <= w_i <= v ...

  3. POJ - 2976 Dropping tests && 0/1 分数规划

    POJ - 2976 Dropping tests 你有 \(n\) 次考试成绩, 定义考试平均成绩为 \[\frac{\sum_{i = 1}^{n} a_{i}}{\sum_{i = 1}^{n} ...

  4. POJ 2976 Dropping tests 【01分数规划+二分】

    题目链接:http://poj.org/problem?id=2976 Dropping tests Time Limit: 1000MS   Memory Limit: 65536K Total S ...

  5. POJ 2976 Dropping tests 01分数规划 模板

    Dropping tests   Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6373   Accepted: 2198 ...

  6. POJ 2976 Dropping tests(01分数规划入门)

    Dropping tests Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11367   Accepted: 3962 D ...

  7. POJ 2976 Dropping tests(01分数规划)

    Dropping tests Time Limit: 1000MS   Memory Limit: 65536K Total Submissions:17069   Accepted: 5925 De ...

  8. POJ 2976 Dropping tests (0/1分数规划)

    Dropping tests Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4654   Accepted: 1587 De ...

  9. Poj 2976 Dropping tests(01分数规划 牛顿迭代)

    Dropping tests Time Limit: 1000MS Memory Limit: 65536K Description In a certain course, you take n t ...

随机推荐

  1. C#获取网页内容的三种方式(转)

    搜索网络,发现C#通常有三种方法获取网页内容,使用WebClient.WebBrowser或者HttpWebRequest/HttpWebResponse... 方法一:使用WebClient (引用 ...

  2. table表格隔行变色

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. ABAP 给动态变量赋值

    [转自 http://blog.csdn.net/forever_crazy/article/details/6544830] 需求: 有时写程序的时候,需要给某个动态变量 赋值操作,当字段比较多时, ...

  4. MySQL——存储引擎

    核心知识点 1.InnoDB:数据和索引存放在单独的文件,聚簇索引,行级锁,事务,MVCC 2.MyISAM: (1)缺点:不支持事务和表级锁,因为不支持表锁,锁颗粒比较大,因此适合只读和小文件. ( ...

  5. 怎么样写一个能告诉你npm包名字是否被占用的工具

    事情是这样的: 因为我经常会写一些npm包,但是有时候我写完一个包,npm publish 的时候却被提示说包名字被占用了,要不就改名字,要不就加scope,很无奈.npm 命令行可以通过 npm v ...

  6. debian下烧写stm32f429I discovery裸机程序

    需要安装openocd软件.如果已安装默认的openocd,需要先卸载系统默认的openocd(默认版本是0.5.0,版本太低),然后再安装. 在安装前需要安装libusb库文件: -dev libu ...

  7. 51nod 1533 && CF538F

    题目:难以简述,请传送门 神犇题解Ⅰ   神犇题解Ⅱ 好劲啊跪在地上..完全没接触过K叉树的性质.. 对于每个询问,我们并不关心叶节点,只关心其他的节点.而一个完整K叉树的内节点个数是O(n/k)的, ...

  8. BZOJ 1198 [HNOI2006]军机调度:dfs

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1198 题意: 有n个雇佣军,m个任务. 第i个雇佣军能够参加cnt个任务,分别为temp[ ...

  9. 一些flag

    连续两道组合计数题 WA 在杨辉三角上,TM 我要是联赛杨辉三角萎了就剁*. 又连续两道题萎在数组越界上,TM 我要是联赛数组越界就吃*.

  10. windows与Linux操作系统的差别

    用户需要记住:Linux和Windows在设计上就存在哲学性的区别.Windows操作系统 倾向于将更多的功能集成到操作系统内部,并将程序与内核相结合:而Linux不同 于Windows,它的内核空间 ...