标签:hdu1203
10 3 4 0.1 4 0.2 5 0.3 0 0
44.0%HintYou should use printf("%%") to print a ‘%‘.
#include <stdio.h> #include <algorithm> #define maxn 10002 using namespace std; struct Node{ int w; double v, pos; } arr[maxn]; bool cmp(Node a, Node b){ return a.pos > b.pos; } int main() { int n, m, i; double ans; while(scanf("%d%d", &n, &m), n || m){ for(i = 0; i < m; ++i){ scanf("%d%lf", &arr[i].w, &arr[i].v); arr[i].pos = arr[i].v / arr[i].w; } sort(arr, arr + m, cmp); ans = 1; for(i = 0; i < m; ++i){ if(n >= arr[i].w){ n -= arr[i].w; ans *= (1.0 - arr[i].v); }else break; } printf("%.1lf%%\n", 100.0 * (1 - ans)); } return 0; }
HDU1203 I NEED A OFFER! 【贪心】,布布扣,bubuko.com
标签:hdu1203
原文地址:http://blog.csdn.net/chang_mu/article/details/38541047