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[4]={1,0,-1,0},dy[4]={0,1,0,-1}; const double INF=0x3f3f3f3f; const ll mod=1e9+7; ll powmod(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)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[100005]; bool cmp(point x,point y){ return x.c>y.c; } bool C(double x){ double sum=0; rep(i,0,n){ p[i].c=p[i].v-p[i].w*x; } sort(p,p+n,cmp); rep(i,0,k){ sum+=p[i].c; } return sum>=0; } int main(){ in2(n,k); rep(i,0,n){ inlf2(p[i].v,p[i].w); p[i].num=i; } double lb=0,ub=INF; rep(i,0,100){ double mid=(lb+ub)/2; if(C(mid)) lb=mid; else ub=mid; } rep(i,0,k){ printf("%d\n",p[i].num+1);编号加一 } return 0; }
时间: 2024-10-25 22:21:00