【题目链接】

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的更多相关文章

  1. 【poj 2976】Dropping tests(算法效率--01分数规划 模版题+二分){附【转】01分数规划问题}

    P.S.又是一个抽时间学了2个小时的新东西......讲解在上半部分,题解在下半部分. 先说一下转的原文:http://www.cnblogs.com/perseawe/archive/2012/05 ...

  2. 【POJ2976】Dropping Tests(分数规划)

    [POJ2976]Dropping Tests(分数规划) 题面 Vjudge 翻译在\(Vjudge\)上有(而且很皮) 题解 简单的\(01\)分数规划 需要我们做的是最大化\(\frac{\su ...

  3. bzoj 2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...

  4. 【链表】BZOJ 2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 382  Solved: 111[Submit][S ...

  5. BZOJ2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 284  Solved: 82[Submit][St ...

  6. BZOJ2293: 【POJ Challenge】吉他英雄

    2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 80  Solved: 59[Submit][Stat ...

  7. BZOJ2287: 【POJ Challenge】消失之物

    2287: [POJ Challenge]消失之物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 254  Solved: 140[Submit][S ...

  8. BZOJ2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 126  Solved: 90[Submit][Sta ...

  9. BZOJ2296: 【POJ Challenge】随机种子

    2296: [POJ Challenge]随机种子 Time Limit: 1 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 114  Solv ...

随机推荐

  1. bootstrap表格样式

    一:表格基本格式 <table> <tr> <th>标题一</th> <th>标题二</th> </tr> < ...

  2. Eclipse的菜单简介

    在Eclipse工作台的上方提供了菜单栏,该菜单栏包含了实现Eclipse各项功能的命令,并且与编辑器相关,即菜单栏中的菜单项与当前编辑器内打开的文件是关联的.例如,编辑器内没有打开任何文件,那么,将 ...

  3. Linux系统下通过命令行对mysql数据进行备份和还原

    一.备份 1.进入mysql目录 cd /var/lib/mysql (进入mysql目录,根据安装情况会有差别) 2.备份 mysqldump -u root -p密码 数据库名 数据表名 > ...

  4. 配置 Sybase数据源

    1.Start-- > All Programs -- > Sybase - -> Connectivity --> click ‘Open Client Directory ...

  5. 参加EMCL感想

    ECML,全名为欧洲机器学习会议,European Conference on Machine Learning 原文链接:http://blog.sina.com.cn/s/blog_59388e2 ...

  6. iproute2常用命令

    #常用命令 ip link show #显示链路 ip addr show #显示地址(或ifconfig) ip route show #显示路由(route -n) ip neigh show # ...

  7. (转) Arcgis for js加载百度地图

    http://blog.csdn.net/gisshixisheng/article/details/44853709 概述: 在前面的文章里提到了Arcgis for js加载天地图,在本节,继续讲 ...

  8. WPF动态折线图

    此项目源码下载地址:https://github.com/lizhiqiang0204/WpfDynamicChart 效果图如下: 此项目把折线图制作成了一个控件,在主界面设置好参数直接调用即可,下 ...

  9. C#使用OracleDataReader返回DataTable

    string data = string.Empty; DataTable OutDataTable = new DataTable(); OracleDataReader daReader = cm ...

  10. vim/vi编辑器挂到后台ctrl + z

    vim/vi编辑器通过CTRL+z将文件挂在到后台后,如果要再次进入,需通过jobs查看文件的序号,然后通过fg 序号进入文件进行编辑 (BaiduPictureToWord) [master@ins ...