250
class Taxi {
public:
double calc(int maxX, int taxiDis) {
double x, y;
x = min(maxX, taxiDis);
y = taxiDis - x;
return sqrt(x * x + y * y);
}
double maxDis(int maxX, int maxY, int taxiDis) {
double r;
if(maxX + maxY < taxiDis)return -1;
return r = max( calc(maxX, taxiDis), calc(maxY, taxiDis) );
}
};
500
class Dating {
public:
string dates(string c, int k) {
string r;
vector<char> v;
int idx = 0;
for(int i=0; i<c.size(); ++i){
v.push_back( c[i] );
}
char a = 'a', b = 'a';
int j = 0;
while( v.size() ){
idx = (idx + k - 1) % v.size();
a = v[idx];
int tmp = 1 << 22;
for(int i=0; i<v.size(); ++i){
if( islower(a) && islower(v[i]) )continue;
if( isupper(a) && isupper(v[i]) )continue;
int hot = a - v[i] - 'a' - 'A';
if( tmp > abs(hot) ){
tmp = abs(hot);
j = i;
b = v[i];
}
}
if(tmp == (1 << 22))break;
if(idx < j){
v.erase( v.begin() + j );
v.erase( v.begin() + idx );
}
else{
v.erase( v.begin() + idx );
v.erase( v.begin() + j );
--idx;
}
if(r.size()) r += ' ';
r += a;
r += b;
}
return r;
}
};
0 件のコメント :
コメントを投稿