【POJ 2976】 Dropping Tests
【题目链接】
http://poj.org/problem?id=2976
【算法】
0/1分数规划
【代码】
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stack>
#include <limits.h>
using namespace std;
#define MAXN 1010
const double eps = 1e-; int i,n,k;
double l,r,mid,ans;
long long a[MAXN],b[MAXN];
double d[MAXN]; inline bool cmp(double a,double b)
{
return a > b;
}
inline bool check()
{
int i;
double sum = ;
sort(d+,d+n+,cmp);
for (i = ; i <= n - k; i++) sum += d[i];
return sum >= ;
} int main()
{ while (scanf("%d%d",&n,&k) != EOF && !(n == && k == ))
{
for (i = ; i <= n; i++) scanf("%lld",&a[i]);
for (i = ; i <= n; i++) scanf("%lld",&b[i]);
l = ; r = ;
ans = ;
while (r - l > eps)
{
mid = (l + r) / 2.0;
for (i = ; i <= n; i++) d[i] = 1.0 * a[i] - mid * b[i];
if (check())
{
l = mid;
ans = mid;
} else r = mid;
}
printf("%lld\n",(long long)(ans*+0.5));
} return ; }
【POJ 2976】 Dropping Tests的更多相关文章
- 【poj 2976】Dropping tests(算法效率--01分数规划 模版题+二分){附【转】01分数规划问题}
P.S.又是一个抽时间学了2个小时的新东西......讲解在上半部分,题解在下半部分. 先说一下转的原文:http://www.cnblogs.com/perseawe/archive/2012/05 ...
- 【POJ2976】Dropping Tests(分数规划)
[POJ2976]Dropping Tests(分数规划) 题面 Vjudge 翻译在\(Vjudge\)上有(而且很皮) 题解 简单的\(01\)分数规划 需要我们做的是最大化\(\frac{\su ...
- bzoj 2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...
- 【链表】BZOJ 2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 382 Solved: 111[Submit][S ...
- BZOJ2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 284 Solved: 82[Submit][St ...
- BZOJ2293: 【POJ Challenge】吉他英雄
2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 80 Solved: 59[Submit][Stat ...
- BZOJ2287: 【POJ Challenge】消失之物
2287: [POJ Challenge]消失之物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 254 Solved: 140[Submit][S ...
- BZOJ2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 126 Solved: 90[Submit][Sta ...
- BZOJ2296: 【POJ Challenge】随机种子
2296: [POJ Challenge]随机种子 Time Limit: 1 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 114 Solv ...
随机推荐
- CSS的常用属性(三)
静态定位 position: static (默认) 标准流 绝对定位 position: absolute 特点: 元素使用绝对定位之后,不占据原来的位置(脱标) 元素使用绝对定位,位置是从浏览器出 ...
- SecureCRT连接Ubuntu报The remote system refused the connection.解决方案
使用SecureCRT连接到远程Ubuntu,连接失败报The remote system refused the connection. 进入Ubuntu系统,终端中敲入以下命令: ps -ef|g ...
- [原创]PM2使nodejs应用随系统启动
1.安装 npm install pm2 -gd 2.启动 pm2 start ./bin/www 3.pm2 save 4.pm2 startup 5.pm2 save 注:上面几个步骤有几个坑: ...
- IVVI SK3-02小骨酷派SK3-02 进入第三方 recovery 刷机 ROOT
首先下载好工具:http://url.cn/5AS7IiB 备用连接 :https://pan.baidu.com/s/1jJmbYAi 本篇教程教你如何傻瓜式解锁BootLoader并进入临时rec ...
- openMSP430之Custom linker script
The use of the -mmcu switch is of course NOT mandatory. It is simply a convenient way to use the pre ...
- SpringBoot入门系列(转)
SpringBoot入门系列:第一篇 Hello World http://blog.csdn.net/lxhjh/article/details/51711148
- eclipse快捷键:
打开快捷键提示: ctrl + shift + L; 自动补全代码: Alt + /; 快速修复: ctrl + 1; 导包: ctrl + shift + o; 格式化代码: ctrl + shif ...
- PJAX全局无刷新的设置方法~
先添加必要文件: <script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></scrip ...
- matlab学习checkbox使用
添加radiobutton1和checkbox2控件以及两个edittextbox控件 %得到控件的值var=get(handles.kj2,'value');%将数值显示到文本框中,将得到的数值转换 ...
- tomcat配置SSH加密
[root@tomcat2 ~]# keytool -genkeypair -alias tomcat -keyalg RSA -keystore /usr/local/tomcat7/keystor ...