【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 ...
随机推荐
- 浅谈html运行原理
浅谈HTML运行原理,所谓的HTML简单的来说就是一个网页,虽然第一节就讲html原理可能大家会听不懂,就当是给一个初步印象把,至少大概知道一个网页的运行流程是怎样的,下面上一张图: 大致的一个htm ...
- springboot + sharding-jdbc 学习
官网地址:http://shardingsphere.io/document/current/cn/overview/ sharding-jdbc事务:https://blog.csdn.net/ya ...
- Leetcode0100--Same Tree 相同树
[转载请注明]http://www.cnblogs.com/igoslly/p/8707664.html 来看一下题目: Given two binary trees, write a functio ...
- 怎么不让别人ping服务器
频繁地使用Ping命令会导致网络堵塞.降低传输效率,为了避免恶意的网络攻击,一般都会拒绝用户Ping服务器.为实现这一目的,不仅可以在防火墙中进 行设置,也可以在路由器上进行设置,并且还可以利用Win ...
- 去除安卓apk中的广告
一般来说,安卓应用很多免费的apk都是有广告的.尽管我们要坚持尊重开发者,帮帮他们点击广告赚钱来可持续发展,但是有的时候,很多游戏中游戏实在是太影响感觉了,当找不到汉化破解版本的时候,也许需要亲自把它 ...
- POJ_2186_Popular Cows_强连通分量
Popular Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 30680 Accepted: 12445 De ...
- vue实现单页应用demo
vue + webpack +ES6/7 + axiso + vuex + vue-router构建项目前端,node + express + mongodb 开发后台 项目demo地址 https: ...
- BZOJ 3319: 黑白树 树+并查集+未调完+神题
Code: #include<bits/stdc++.h> #define maxn 1000003 using namespace std; char *p1,*p2,buf[10000 ...
- S-HR快速查看shr日志
http://localhost:6888/shr/appData.do?method=getApplicationLog&logFile=apusic.log.0&instance= ...
- 【深度学习框架】使用PyTorch进行数据处理
在深度学习中,数据的处理对于神经网络的训练来说十分重要,良好的数据(包括图像.文本.语音等)处理不仅可以加速模型的训练,同时也直接关系到模型的效果.本文以处理图像数据为例,记录一些使用PyTorc ...