【题目链接】

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. 简单ajax库

    function TuziAjax(reqType,url,fnoK, fnFail) { var xmlHttp = null; if (window.XMLHttpRequest) { xmlHt ...

  2. 前端HTML5思维导图笔记

    看不清的朋友右键保存或者新窗口打开哦!热爱学习前端,喜欢我可以关注我,更多的思维导图笔记

  3. 后端springmvc,前端html5的FormData实现文件断点上传

    前言 最近项目中有使用到文件断点上传,得空便总结总结,顺便记录一下,毕竟“好记性不如烂笔头”. 后端代码: package com.test.controller; import java.io.Bu ...

  4. DNN:windows使用 YOLO V1,V2

    本文有修改,如有疑问,请移步原文. 原文链接:  YOLO v1之总结篇(linux+windows) 此外:  YOLO-V2总结篇   Yolo9000的改进还是非常大的 由于原版的官方YOLOv ...

  5. Arduino 9g舵机操作

    一.接线原理图 一.实物图 三.事例代码 从0转180度,再从180转到0度

  6. HDU_5724_状态压缩的sg函数

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5724 题目大意:n行20列的棋盘,对于每行,如果当前棋子右边没棋子,那可以直接放到右边,如果有就跳过放 ...

  7. sqlitManager

    @interface sqlitManager : NSObject +(instancetype)sharedSqlitManager; -(void)createDB; -(void)create ...

  8. C# MVC 延时

    [System.Runtime.InteropServices.DllImport("kernel32.dll")] static extern uint GetTickCount ...

  9. 数据清理,预处理 pandas dataframe 操作技巧 总结

    dsoft2 = data1.loc[(data1['程'] == "轻") | (data1['程'] == "中")]设置x下标plt.xticks(np. ...

  10. XML文件读取加上 Ajax请求

    #region XML文件处理 XmlDocument doc = new XmlDocument(); XmlReaderSettings settings = new XmlReaderSetti ...