Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
为什么WA了,谁能帮我看看。。。#include<stdio.h> #include<algorithm> using namespace std; const int maxN = 100000+5; const double minl = 0; const double maxr = 10000000+0.0001; struct J{ int id; double b; bool operator < (const struct J &A) const{ return b > A.b; } }jewels[maxN]; int N, K; bool isOk(){ double ans=0; for(int i=1; i<=K; i++){ ans += jewels[i].b; } return ans >= 0.0; } int main(){ int ans[maxN]; double v[maxN], w[maxN]; scanf("%d%d", &N, &K); for(int i=1; i<=N; i++) scanf("%lf%lf", &v[i], &w[i]); double l, r; l = minl; r = maxr; while(r-l>=1e-8){ double x = (l + r) * 0.5; for(int k=1; k<=N; k++){ jewels[k].id = k; jewels[k].b = v[k] - x * w[k]; } sort(jewels+1, jewels+1+N); if(isOk()){ l = x; for(int i=1; i<=K; i++) ans[i] = jewels[i].id; } else r = x; } for(int i=1; i<=K; i++) printf("%d ", ans[i]); printf("\n"); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator