POJ3111 K Best(另类背包+二分+变态精度)
POJ3111 K Best,看讨论区说数据有点变态,精度要求较高,我就直接把循环写成了100次,6100ms过,(试了一下30,40都会wa,50是4000ms)
第一次在POJ上看到下面这种东西还是很好奇的,
一个题目可以接受多种正确答案,即有多组解的时候,题目就必须被Special Judge.
Special Judge程序使用输入数据和一些其他信息来判答你程序的输出,并将判答结果返回.
| Case Time Limit: 2000MS | Special Judge |
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <fstream>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define in(n) scanf("%d",&(n))
#define in2(x1,x2) scanf("%d%d",&(x1),&(x2))
#define inll(n) scanf("%I64d",&(n))
#define inll2(x1,x2) scanf("%I64d%I64d",&(x1),&(x2))
#define inlld(n) scanf("%lld",&(n))
#define inlld2(x1,x2) scanf("%lld%lld",&(x1),&(x2))
#define inf(n) scanf("%f",&(n))
#define inf2(x1,x2) scanf("%f%f",&(x1),&(x2))
#define inlf(n) scanf("%lf",&(n))
#define inlf2(x1,x2) scanf("%lf%lf",&(x1),&(x2))
#define inc(str) scanf("%c",&(str))
#define ins(str) scanf("%s",(str))
#define out(x) printf("%d\n",(x))
#define out2(x1,x2) printf("%d %d\n",(x1),(x2))
#define outf(x) printf("%f\n",(x))
#define outlf(x) printf("%lf\n",(x))
#define outlf2(x1,x2) printf("%lf %lf\n",(x1),(x2));
#define outll(x) printf("%I64d\n",(x))
#define outlld(x) printf("%lld\n",(x))
#define outc(str) printf("%c\n",(str))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define mem(X,Y) memset(X,Y,sizeof(X));
typedef vector<int> vec;
typedef long long ll;
typedef pair<int,int> P;
const int dx[]={,,-,},dy[]={,,,-};
const double INF=0x3f3f3f3f;
const ll mod=1e9+;
ll powmod(ll a,ll b) {ll res=;a%=mod;for(;b;b>>=){if(b&)res=res*a%mod;a=a*a%mod;}return res;}
const bool AC=true; int n,k;
struct point{
double w,v,c;
int num; //保存编号,便于输出答案
};
point p[];
bool cmp(point x,point y){
return x.c>y.c;
}
bool C(double x){
double sum=;
rep(i,,n){
p[i].c=p[i].v-p[i].w*x;
}
sort(p,p+n,cmp);
rep(i,,k){
sum+=p[i].c;
}
return sum>=;
}
int main(){
in2(n,k);
rep(i,,n){
inlf2(p[i].v,p[i].w);
p[i].num=i;
}
double lb=,ub=INF; rep(i,,){
double mid=(lb+ub)/;
if(C(mid)) lb=mid;
else ub=mid;
}
rep(i,,k){
printf("%d\n",p[i].num+);编号加一
}
return ;
}
POJ3111 K Best(另类背包+二分+变态精度)的更多相关文章
- Inviting Friends(hdu3244 && zoj3187)完全背包+二分
Inviting Friends Time Limit: 1 Second Memory Limit: 32768 KB You want to hold a birthday party, invi ...
- 机器学习理论与实战(十)K均值聚类和二分K均值聚类
接下来就要说下无监督机器学习方法,所谓无监督机器学习前面也说过,就是没有标签的情况,对样本数据进行聚类分析.关联性分析等.主要包括K均值聚类(K-means clustering)和关联分析,这两大类 ...
- poj 3111 K Best 最大化平均值 二分思想
poj 3111 K Best 最大化平均值 二分思想 题目链接: http://poj.org/problem?id=3111 思路: 挑战程序竞赛书上讲的很好,下面的解释也基本来源于此书 设定条件 ...
- 第K大01背包
其实这个问题,真的挺好想的,但是我咋想了那么久呢~~ 很好理解,第K大01背包一定基于01背包,dp数组也很容易的想到由dp[V] ----> dp[V][K],来表示背包容量是V时候的第 ...
- 计蒜客 38229.Distance on the tree-1.树链剖分(边权)+可持久化线段树(区间小于等于k的数的个数)+离散化+离线处理 or 2.树上第k大(主席树)+二分+离散化+在线查询 (The Preliminary Contest for ICPC China Nanchang National Invitational 南昌邀请赛网络赛)
Distance on the tree DSM(Data Structure Master) once learned about tree when he was preparing for NO ...
- [POJ3111]K Best(分数规划, 二分)
题目链接:http://poj.org/problem?id=3111 求选k对数,使得上述式子值最大.容易想到设左边为一个值,对式子变形以下,得到sigma(v-r*w))==0的时候就是最大的,& ...
- poj3111 K Best 最大化平均值,二分
题目:http://poj.org/problem?id=3111 题意:给你n,k,n个数的v.w值,选出k个数,使得v之和/w之和最大化. 思路:一看到题目,这不是赤果果的贪心吗?为什么放在二分专 ...
- HDU 1007 Quoit Design(二分+浮点数精度控制)
Quoit Design Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- POJ 1064 Cable master(二分查找+精度)(神坑题)
POJ 1064 Cable master 一开始把 int C(double x) 里面写成了 int C(int x) ,莫名奇妙竟然过了样例,交了以后直接就wa. 后来发现又把二分查找的判断条 ...
随机推荐
- ASP.NET MVC学习之路:模板页
1.MVC开发步骤: 控制器-视图. 2.每一个视图都会有一个默认的模板页:_ViewStart.cshtml. 名字不能改,只能叫_ViewStart. 3.Layout=”~/Views/Shar ...
- codevs 1068 乌龟棋
题目描述 Description 小明过生日的时候,爸爸送给他一副乌龟棋当作礼物. 乌龟棋的棋盘是一行N个格子,每个格子上一个分数(非负整数).棋盘第1格是唯一 的起点,第N格是终点,游戏要求玩家控制 ...
- C#的Reflection总结
什么是反射 在.NET中的反射也可以实现从对象的外部来了解对象(或程序集)内部结构的功能,哪怕你不知道这个对象(或程序集)是个什么东西,另外.NET中的反射还可以运态创建出对象并执行它其中的方法. 反 ...
- ulimit小结
1. limits是一个进程的资源,会被子进程继承 2. soft limit -S, hard limits -H hard limits只能被root用户修改,启动的时候会加载配置/etc/s ...
- Altium Designer 14(或者其他版本)里更改PCB板(图纸)大小
1.在PCB板界面下方有一行不同颜色的图层选项,找到“Keep-Out Layer”,没看见的话点击右箭头即可找到. 2.在“Place”选项里面选择“line”,也就是添加线,把你所有元件用线条 ...
- myEclipse异常解决:Errors occurred during the build. Errors running builder Mule 3 hot deployment
选择一个项目—-右键Properties—-Builders—-取消 “JavaScript Validator” 和 Mule 3 hot deployment 的勾就OK了 根据具体异常,勾选. ...
- oschina BI商业智能开源软件
54款 BI商业智能开源软件 MySQL数据仓库解决方案 Infobright OLAP 分析引擎 Apache Kylin 数据处理和分发系统 Apache NiFi OLAP 数据查询引擎 Dru ...
- locate,nl命令
locate 命令 locate 让使用者可以很快速的搜寻档案系统内是否有指定的档案.其方法是先建立一个包括系统内所有档案名称及路径的数据库,之后当寻找时就只需查询这个数据库,而不必实际深入档案系统之 ...
- UML[1] UML类图关系(泛化 、继承、实现、依赖、关联、聚合、组合)(转)
转自:http://blog.csdn.net/zhaoxu0312/article/details/7212152 继承.实现.依赖.关联.聚合.组合的联系与区别 分别介绍这几种关系: 继承 指的是 ...
- 接上一篇博客(解决-Dmaven.multiModuleProjectDirectory system property is not set. Check $M2_HOME environment variable and mvn script match. )
解决-Dmaven.multiModuleProjectDirectory system property is not set. Check $M2_HOME environment variabl ...