tcbpg

Untitled

Aug 23rd, 2011
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <algorithm>
  5. #include <cmath>
  6.  
  7. using namespace std;
  8.  
  9. #define forn(i, n) for(int i = 0; i < (int) (n); i++)
  10. const double eps = 1e-4;
  11.  
  12. int main(){
  13. #ifdef ACM
  14.     freopen("test.in", "r", stdin);
  15. #endif
  16.  
  17.     double s[16], e[16]; int n;
  18.     int counter = 1;
  19.  
  20.     while(scanf("%d", &n) && n != 0){
  21.         forn(i, n){
  22.             scanf("%lf %lf", &s[i], &e[i]);
  23.         }
  24.  
  25.         double l = 0, r = 1440*60;
  26.         while(r-l > eps){
  27.             double m = (l + r)/2;
  28.  
  29.             vector<int> perm;
  30.             forn(i, n) perm.push_back(i);
  31.  
  32.             bool ok = false;
  33.             do{
  34.                 double d = s[ perm[0] ];
  35.                 bool allset = true;
  36.  
  37.                 forn(i, n){
  38.                     if(d <= e[ perm[i] ]){
  39.                         d = max(s[ perm[i] ], d)+m;
  40.                     }else{
  41.                         allset = false;
  42.                         break;
  43.                     }
  44.                 }
  45.  
  46.                 if(allset){ ok = true; break; }
  47.             }while(next_permutation(perm.begin(), perm.end()));
  48.  
  49.             if(ok) l = m; else r = m;
  50.         }
  51.  
  52.         int hours = (int) l;
  53.         int mins = round((l - hours)*60.0);
  54.         if(mins == 60) hours++, mins = 0;
  55.  
  56.         printf("Case %d: %d:%02d\n", counter++, hours, mins);
  57.     }
  58.  
  59.  
  60.     return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment