解いた問題

5/08/2011

SRM325Div2

250
class SalaryCalculator {
public:
  double calcHours(int P1, int P2, int salary) {
    double s = 0.00000000001, b = 1e200;
    for(int n = 10000; n--; ){
      double c = (s + b) / 2.0;
      double p = min((double)c, 200.0)*(double)P1 + max((double)c - 200.0, 0.0)*(double)P2;
      if( p < salary )s = c;
      else b = c;
    }   
    return s;
  }
}; 
500
class RGBStreet {
public:
  int estimateCost(vector <string> h) {
    const int size = h.size();
    const int R = 0, G = 1, B = 2;
    
    int cost[size][3];
    for(int i=0; i<h.size(); ++i){
      istringstream iss( h[i] );
      iss >> cost[i][R] >> cost[i][G] >> cost[i][B];
    }

    const int inf = 1 << 25;
    int t[size][3];
    fill( &t[0][0], &t[size-1][3], inf );

    t[0][R] = cost[0][R];
    t[0][G] = cost[0][G];
    t[0][B] = cost[0][B];
    
    for(int i=1; i<size; ++i){
      for(int j=0; j<3; ++j){
        for(int k=0; k<3; ++k){
          if(j == k)continue;
          t[i][k] = min(t[i][k], t[i-1][j] + cost[i][k]);
        }
      }
    }

    return min( t[size-1][R], min( t[size-1][G], t[size-1][B] ) );
  }
};
1000
うーむ。

0 件のコメント :

コメントを投稿