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", &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)