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(另类背包+二分+变态精度)的更多相关文章

  1. Inviting Friends(hdu3244 && zoj3187)完全背包+二分

    Inviting Friends Time Limit: 1 Second Memory Limit: 32768 KB You want to hold a birthday party, invi ...

  2. 机器学习理论与实战(十)K均值聚类和二分K均值聚类

    接下来就要说下无监督机器学习方法,所谓无监督机器学习前面也说过,就是没有标签的情况,对样本数据进行聚类分析.关联性分析等.主要包括K均值聚类(K-means clustering)和关联分析,这两大类 ...

  3. poj 3111 K Best 最大化平均值 二分思想

    poj 3111 K Best 最大化平均值 二分思想 题目链接: http://poj.org/problem?id=3111 思路: 挑战程序竞赛书上讲的很好,下面的解释也基本来源于此书 设定条件 ...

  4. 第K大01背包

    其实这个问题,真的挺好想的,但是我咋想了那么久呢~~ 很好理解,第K大01背包一定基于01背包,dp数组也很容易的想到由dp[V]  ---->   dp[V][K],来表示背包容量是V时候的第 ...

  5. 计蒜客 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 ...

  6. [POJ3111]K Best(分数规划, 二分)

    题目链接:http://poj.org/problem?id=3111 求选k对数,使得上述式子值最大.容易想到设左边为一个值,对式子变形以下,得到sigma(v-r*w))==0的时候就是最大的,& ...

  7. poj3111 K Best 最大化平均值,二分

    题目:http://poj.org/problem?id=3111 题意:给你n,k,n个数的v.w值,选出k个数,使得v之和/w之和最大化. 思路:一看到题目,这不是赤果果的贪心吗?为什么放在二分专 ...

  8. HDU 1007 Quoit Design(二分+浮点数精度控制)

    Quoit Design Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  9. POJ 1064 Cable master(二分查找+精度)(神坑题)

    POJ 1064 Cable master 一开始把 int C(double x) 里面写成了  int C(int x) ,莫名奇妙竟然过了样例,交了以后直接就wa. 后来发现又把二分查找的判断条 ...

随机推荐

  1. 工作中用到的Jquery特效

    jQuery缓慢弹出下拉tab导航 http://sc.chinaz.com/jiaoben/130811578701.htm

  2. JS encode decode

    网上查到的全都是escape,和需要的编码不是一回事,好不容易找到的结果 保存下来以备以后使用 js对文字进行编码涉及3个函数:escape,encodeURI,encodeURIComponent, ...

  3. 【行为型】Interpreter模式

    解释器模式意图为给定的语言定义其文法表示,同时定义该文法表示的一套解释器来解释语言中的句子.该模式说的简单通俗点,其主要用途是用来解释用的.至于解释什么,则要看具体的上下文环境.我们可以为一个表达式专 ...

  4. Windows 批处理文件

    窗口自动关闭:批处理文件执行完之后,窗口会自动关闭,若想执行完之后,窗口不自动关闭的话,在文件末尾添加1. 批处理文件执行完之后,窗口会自动关闭2. 若想执行完之后,窗口不自动关闭的话,在文件末尾添加 ...

  5. MMDrawerController 使用遇到的问题及定制

    MMDrawerController 1,集成UIViewController * leftDrawer = [[UIViewController alloc] init]; UIViewContro ...

  6. LPC1758串口ISP下载程序

    最近手上拿到一块人家公司做的3D打印机的板子,用的核心芯片是LPC1758,板上引出了ISP下载接口.那接口共4个引出脚,如下图所示:   其中ME_EN引脚又连接到了芯片的P2[10]引脚,那个引脚 ...

  7. Entity Framework with MySQL 学习笔记一(继承)

    基本上sql中要表示继承关系有3中方式. 分别是,1表继承(TPH),2表继承(TPC),3表继承(TPT) 1表 : Person id type name classroom office 1 s ...

  8. Sum square difference

    简单: e sum of the squares of the first ten natural numbers is, 12 + 22 + ... + 102 = 385 The square o ...

  9. BZOJ 4407 于神之怒加强版

    http://www.lydsy.com/JudgeOnline/problem.php?id=4407 题意: 给下N,M,K.求 思路:  来自:http://blog.csdn.net/ws_y ...

  10. BZOJ 1211 树的计数

    http://www.lydsy.com/JudgeOnline/problem.php?id=1211 思路:每一个prufer编码都代表了一棵树,而点的度数,代表了它在prufer编码中出现的次数 ...