【题目链接】

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. L4课程_Firebase_笔记分享_StudyJams_2017

    最近才发现Study Jams China的官方论坛也支持MarkDown,所以就直接把笔记发在了那儿. http://www.studyjamscn.com/thread-21855-1-1.htm ...

  2. Block的本质与使用

    1.block的基本概念及使用 blcok是一种特殊的数据结构,它可以保存一段代码,等到需要的时候进行调用执行这段代码,常用于GCD.动画.排序及各类回调. Block变量的声明格式为: 返回值类型( ...

  3. Sql语句优化-查询两表不同行NOT IN、NOT EXISTS、连接查询Left Join

    在实际开发中,我们往往需要比较两个或多个表数据的差别,比较那些数据相同那些数据不相同,这时我们有一下三种方法可以使用:1. IN或NOT IN,2. EXIST或NOTEXIST,3.使用连接查询(i ...

  4. 使用cookies查询商品详情

    易买网项目完工,把一些新知识记录下来,以便以后查阅,也方便他人借阅.介绍使用cookies查询商品详情. 第一步:建立商品实体类. 第二步:连接Oracle数据库. 第三步:使用三层架构. 效果图如下 ...

  5. 经典实用SQL Server语句大全总结(一)

    简要介绍基础语句:1.说明:创建数据库CREATE DATABASE database-name2.说明:删除数据库drop database dbname3.说明:备份sql server--- 创 ...

  6. CNN结构:MXNet设计和实现简介

    对原文有大量修改,如有疑惑,请移步原文. 参考链接:MXNet设计和实现简介 文章翻译于:https://mxnet.incubator.apache.org/architecture/index.h ...

  7. 微信小程序中的iPhone X适配问题

    微信小程序中的iPhone X适配问题 小程序中下方的导航会被iPhone X下面的那条黑线盖住[微笑脸],所以要专门为了iPhone X做样式上的适配[微笑脸] wx.getSystemInfo({ ...

  8. Apache2.2 启动和停止命令

    1.启动:net start apache2.2 2.停止:net stop apache2.2

  9. 磁盘及文件系统管理(以及btrfs)

    Linux系统管理 磁盘分区及文件系统管理 raid lvm 网络属性管理 程序包管理 sed及awk 进程查看和管理 内核管理(内核的编译和安装) 系统启动流程 定制,编译内核,busybox 系统 ...

  10. luogu P4512 多项式除法 (模板题、FFT、多项式求逆)

    手动博客搬家: 本文发表于20181206 14:42:53, 原地址https://blog.csdn.net/suncongbo/article/details/84853342 题目链接: ht ...