Uva_live 3664 (Precision Pit)

Source: Internet
Author: User

Test instructions is a good understanding of the greedy problem, but the accuracy of the card crazy pits.

Again understand the double decimal operation can lead to the precision problem, to avoid this problem can be multiplied by 100 as an integer comparison, the output time divided by 100 OK;

Thought is also very good to think, the data is not big, directly paste code bar.

1#include <cstdio>2#include <iostream>3#include <sstream>4#include <cmath>5#include <cstring>6#include <cstdlib>7#include <string>8#include <vector>9#include <map>Ten#include <Set> One#include <queue> A#include <stack> -#include <algorithm> - using namespacestd; the #definell Long Long - #define_cle (M, a) memset (M, A, sizeof (m)) - #defineRepu (I, A, b) for (int i = A; I < b; i++) - #defineREPD (I, A, b) for (int i = b; i >= A; i--) + #defineSFI (n) scanf ("%d", &n) - #definePFI (n) printf ("%d\n", N) + #defineMAXN 100010 A Const intMAXN =16400; at structPlayer - { -     DoubleA, B, C; -     intMax_; -     Set<int>s; - } P[MAXN]; in intR[MAXN], VIS[MAXN]; - intMain () to { +     intN; -     intT =1; the      while(~SCANF ("%d", &n) &&N) *     { $          for(inti =0; I <= N; i++)Panax Notoginseng p[i].s.clear (); -          for(inti =1; I <= N; i++) the         { +scanf"%LF%LF%LF", &AMP;P[I].A, &p[i].b, &p[i].c); A             intA = (p[i].a+0.005)* -;//Note that the accuracy of this control is in order to rounding the             intb = (p[i].b+0.005)* -; +             intc = (p[i].c+0.005)* -; -  $ P[i].s.insert (a); $ P[i].s.insert (b); - P[i].s.insert (c); -P[i].s.insert (A +b); theP[i].s.insert (A +c); -P[i].s.insert (b +c);WuyiP[i].s.insert (a+b+c); theP[i].s.insert (0); -P[i].max_ = a+b+C; Wu         } -         BOOLOK =true; About          for(inti =0; I < n; i++) $         { -scanf"%d", &r[i]); -         } -         intAns = p[r[0]].max_; A          for(inti =1; I < n; i++) +         { the             intLast = r[i-1], now =R[i]; -             if(Last >Now ) $             { the                 if(*p[now].s.begin () >=ans) the                 { theOK =false; the                      Break; -                 } in                 Set<int>::iterator it =p[now].s.lower_bound (ans); theit--; theAns = *it; About             } the             Else the             { the                 if(*p[now].s.begin () >ans) +                 { -OK =false; the                      Break;Bayi                 } the                 Set<int>::iterator it =p[now].s.lower_bound (ans); the                 if(It = = P[now].s.end () | | *it >ans) -                 { ---it; theAns = *it; the                 } the             } the         } -         if(OK) the         { theprintf"Case %d:%.2lf\n", t++, (Double) ans/100.00); the         }94         Else the         { theprintf"Case %d:no solution\n", t++); the         }98     } About     return 0; -}
View Code

Uva_live 3664 (Precision Pit)

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.