交互に(同じ色同士は触れない様に)使うという条件があるので、赤からと青からの2通りを試す。
int solve(double w, double h, vector<int> a, vector<int> b)
{
vector<double> v;
for(int i=0; i<min(a.size(), b.size()); ++i){
v.push_back( a[i] );
v.push_back( b[i] );
}
if( b.size() < a.size() )v.push_back( a[b.size()] );
double sum = 0;
for(int i=0; i<v.size(); ++i){
if( v[i] < h )break;
sum += sqrt( v[i] * v[i] - h * h );
if( w <= sum )return i+1;
}
return -1;
}
class ColoringRectangle {
public:
int chooseDisks(int width, int height, vector <int> red, vector <int> blue) {
sort( ALL(red) );
reverse( ALL(red) );
sort( ALL(blue) );
reverse( ALL(blue) );
int a = solve( width, height, red, blue );
int b = solve( width, height, blue, red );
if( a == -1 && b == -1 )return -1;
if( a == -1 )return b;
if( b == -1 )return a;
return min( a, b );
}
};
0 件のコメント :
コメントを投稿