Advertisement
Guest User

Untitled

a guest
Apr 16th, 2018
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.76 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define fst first
  4. #define snd second
  5. #define all(x) (x).begin(), (x).end()
  6. #define rall(x) (x).rbegin(), (x).rend()
  7. #define clr(a, v) memset( a , v , sizeof(a) )
  8. #define pb push_back
  9. #define mp make_pair
  10. #define sz size()
  11. #define FORN( i , s , n ) for( int i = (s) ; i < (n) ; i++ )
  12. #define FOR( i , n ) FORN( i , 0 , n )
  13. #define FORIT( i , x ) for( typeof x.begin() i = x.begin() ; i != x.end() ; i++ )
  14. #define trace(x)    cout << #x << ": " << x << endl;
  15. #define trace2(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << endl;
  16. #define trace3(x, y, z) cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
  17. #define read ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  18.  
  19. using namespace std;
  20.  
  21. typedef long long int64;
  22. typedef vector <int> vi;
  23. typedef pair <int,int> ii;
  24. typedef vector <string> vs;
  25. typedef vector <ii> vii;
  26.  
  27. int W[105];
  28. int H[105];
  29.  
  30. int L[105];
  31. double R[105];
  32.  
  33. double maxR[25010];
  34.  
  35. int main(){
  36.     int T,N;
  37.     double P;
  38.     cin>>T;
  39.     FORN(caso, 1, T+1){
  40.         printf("Case #%d: ", caso);
  41.         cin>>N>>P;
  42.         double aux = 0;
  43.         FOR(i,N) {
  44.             cin>>W[i]>>H[i];
  45.             L[i] = min(W[i], H[i]) * 2;
  46.             R[i] = sqrt( W[i]*W[i] + H[i]*H[i] ) * 2.0;
  47.             P -= 2.0*(W[i] + H[i]);
  48.             aux += 2.0*(W[i] + H[i]);
  49.         }
  50.  
  51.         FOR(i, 25005) maxR[i] = -1e18;
  52.  
  53.         maxR[0] = 0.0;
  54.  
  55.  
  56.         FOR(i,N) FORN(j, L[i], 25005) {
  57.             maxR[j] = max ( maxR[j], maxR[j - L[i]] + R[i] );
  58.         }
  59.  
  60.         double ans = 0;
  61.         FOR(i,min((int)P+1,25005)) ans = max ( ans, min( P, maxR[i] ) );
  62.  
  63.         printf("%.08f\n",ans+aux);
  64.  
  65.     }
  66.     return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement