
题面
显然一份食物被传递次数越多,它的贡献就越小
所以我们只要恰好把每只动物都喂饱,剩下的自己吃独食(滑稽)
贪心的选即可
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
using namespace std; int n, r[100010]; double a[100010], b[100010]; int () { scanf("%d%lf", &n, a); b[0] = a[0] / 5; for(int i = 1; i <= n; i++) scanf("%lf%d", a + i, r + i); int now = 0; for(int i = 1; i <= n; i++) { b[i] = a[i] / 5; while(1) { if(now > r[i]) return puts("-1"), 0; if(b[now] >= a[i]) { b[now] -= a[i]; break; } a[i] -= b[now]; now++; } } double ans = 0; for(; now <= n; now++) ans += b[now]; return printf("%.10lf", ans), 0; }
|
近期评论