1612-guess (greedy)

Source: Internet
Author: User

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,&AMP;A[I].B,&AMP;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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.