The idea of the problem is very good, is to try to take a larger number of results for the people behind to leave a larger "space." The details are also very good to think, here no longer repeat, it is worth mentioning is: the problem of precision, resulting in my start has been WA.
Since the input and output only retain two decimal places, we might as well turn the floating-point number into a decimal, where we use the round function to round up the unwanted decimal places to integers.
#include <bits/stdc++.h>using namespace Std;const int maxn = 16384 + 10;int n,rankk[maxn],case = 0;struct Node {d Ouble A,b,c;} A[maxn];int Main () {while (~SCANF ("%d", &n) &&n) {for (int i=1;i<=n;i++) {scanf ("%lf%lf%lf", &a[ I].A,&A[I].B,&A[I].C); a[i].a*=100.0; a[i].b*=100.0; a[i].c*=100.0; } for (int i=1;i<=n;i++) scanf ("%d", &rankk[i]); int cur = a[rankk[1]].a + a[rankk[1]].b + a[rankk[1]].c; bool OK = true; for (int i=2;i<=n;i++) {int cnt[10]; CNT[0] = (int) round (A[RANKK[I]].A); CNT[1] = (int) round (a[rankk[i]].b); CNT[2] = (int) round (A[RANKK[I]].C); CNT[3] = (int) round (a[rankk[i]].a + a[rankk[i]].b); CNT[4] = (int) round (a[rankk[i]].a + a[rankk[i]].c); CNT[5] = (int) round (a[rankk[i]].b + a[rankk[i]].c); CNT[6] = (int) round (a[rankk[i]].a + a[rankk[i]].b + a[rankk[i]].c); CNT[7] = 0; if (Rankk[i] > Rankk[i-1]) {sort (cnt,cnt+8); BOOL Flage = false; for (int i=7;i>=0;i--) {if (Cnt[i] > cur) continue; else {cur = cnt[i]; flage = true; break;} } if (!flage) {ok = false; break;} } else {sort (cnt,cnt+8); BOOL Flage = false; for (int i=7;i>=0;i--) {if (Cnt[i] >= cur) continue; else {cur = cnt[i]; flage = true; break;} } if (!flage) {ok = false; break;} }} printf ("Case%d:", ++case); if (OK) printf ("%.2lf\n", cur/100.0); else printf ("No solution\n"); } return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
1612-guess (greedy)