SRM370 DIV2
: 문제가 길어서 먼말인가 했는데 풀이는 간단;
class Containers
{
public:
int wastedSpace(vector <int> c, vector <int> p)
{
int tot = 0;
REP(i, c.size())
tot += c[i];
REP(i, p.size())
tot -= p[i];
return tot;
}
};
SRM371 DIV2
: 문제파악이 어려웠던 문제. 다시 풀어볼 것.
class CondorcetVoting
{
public:
int winner(vector <string> v)
{
int n = v[0].size();
VI d(n, 0);
REP(i, n)
{
REP(j, n)
{
if(i==j) continue;
int x = 0, y = 0;
REP(k, v.size())
{
if(v[k][i] < v[k][j]) x++;
else if(v[k][i] > v[k][j]) y++;
}
if( x > y) d[i]++;
}
}
int m = 0, index = 0;
REP(i, d.size())
{
if( d[i] > m)
{
m = d[i];
index = i;
}
}
if(m != n-1) return -1;
return index;
}
};
SRM372 DIV2
class DietPlan
{
public:
string chooseDinner(string d, string b, string l)
{
REP(i, b.size())
{
if(d.find(b[i]) == string::npos) return "CHEATER";
d.erase(d.find(b[i]), 1);
}
REP(i, l.size())
{
if(d.find(l[i]) == string::npos) return "CHEATER";
d.erase(d.find(l[i]), 1);
}
sort(ALL(d));
return d;
}
};
SRM373 DIV2
class TheEquation
{
public:
int leastSum(int X, int Y, int P)
{
VI d;
for(int a=1 ; a<= P; a++)
{
for(int b=1; b <=P; b++)
{
if( (a*X+b*Y) % P == 0) d.pb(a+b);
}
}
sort(ALL(d));
return d[0];
}
};
SRM374 DIV2
: 간만에 보는 수학문제
class HockeyFault
{
public:
int numPlayers(int w, int h, int x, int y, vector <int> px, vector <int> py)
{
int ret = 0;
REP(i, px.size())
{
double x1 = px[i];
double y1 = py[i];
if( (x1 >= x && x1 <= x+w && y1 >= y && y1 <= y+h) ||
(sqrt( (x1-x)*(x1-x) + (y1-y-h/2)*(y1-y-h/2)) <= h/2 ) ||
(sqrt((x1-x-w)*(x1-x-w) + (y1-y-h/2)*(y1-y-h/2)) <= h/2 ))
{
ret++;
}
}
return ret;
}
};
SRM375 DIV2
: 약이름에 weighing이 오는걸 생각 못해서 틀림. 문제를 신중히 풀어야 할 문제
참고할 만한 소스 sscanf(ing[i].c_str(), "%d ml of %*[^,], weighing %d g", &a, &b);
class MixtureDensity
{
public:
double getDensity(vector <string> ing)
{
double m =0, v = 0;
REP(i, ing.size())
{
istringstream in(ing[i]);
int a, b;
string t1,t2;
in >> a;
while( in >> t1)
{
if(t1[t1.size()-1] == ',')
{
in >> t2;
break;
}
}
in>> b;
m += a;
v += b;
}
return v/m;
}
};
: 문제가 길어서 먼말인가 했는데 풀이는 간단;
class Containers
{
public:
int wastedSpace(vector <int> c, vector <int> p)
{
int tot = 0;
REP(i, c.size())
tot += c[i];
REP(i, p.size())
tot -= p[i];
return tot;
}
};
SRM371 DIV2
: 문제파악이 어려웠던 문제. 다시 풀어볼 것.
class CondorcetVoting
{
public:
int winner(vector <string> v)
{
int n = v[0].size();
VI d(n, 0);
REP(i, n)
{
REP(j, n)
{
if(i==j) continue;
int x = 0, y = 0;
REP(k, v.size())
{
if(v[k][i] < v[k][j]) x++;
else if(v[k][i] > v[k][j]) y++;
}
if( x > y) d[i]++;
}
}
int m = 0, index = 0;
REP(i, d.size())
{
if( d[i] > m)
{
m = d[i];
index = i;
}
}
if(m != n-1) return -1;
return index;
}
};
SRM372 DIV2
class DietPlan
{
public:
string chooseDinner(string d, string b, string l)
{
REP(i, b.size())
{
if(d.find(b[i]) == string::npos) return "CHEATER";
d.erase(d.find(b[i]), 1);
}
REP(i, l.size())
{
if(d.find(l[i]) == string::npos) return "CHEATER";
d.erase(d.find(l[i]), 1);
}
sort(ALL(d));
return d;
}
};
SRM373 DIV2
class TheEquation
{
public:
int leastSum(int X, int Y, int P)
{
VI d;
for(int a=1 ; a<= P; a++)
{
for(int b=1; b <=P; b++)
{
if( (a*X+b*Y) % P == 0) d.pb(a+b);
}
}
sort(ALL(d));
return d[0];
}
};
SRM374 DIV2
: 간만에 보는 수학문제
class HockeyFault
{
public:
int numPlayers(int w, int h, int x, int y, vector <int> px, vector <int> py)
{
int ret = 0;
REP(i, px.size())
{
double x1 = px[i];
double y1 = py[i];
if( (x1 >= x && x1 <= x+w && y1 >= y && y1 <= y+h) ||
(sqrt( (x1-x)*(x1-x) + (y1-y-h/2)*(y1-y-h/2)) <= h/2 ) ||
(sqrt((x1-x-w)*(x1-x-w) + (y1-y-h/2)*(y1-y-h/2)) <= h/2 ))
{
ret++;
}
}
return ret;
}
};
SRM375 DIV2
: 약이름에 weighing이 오는걸 생각 못해서 틀림. 문제를 신중히 풀어야 할 문제
참고할 만한 소스 sscanf(ing[i].c_str(), "%d ml of %*[^,], weighing %d g", &a, &b);
class MixtureDensity
{
public:
double getDensity(vector <string> ing)
{
double m =0, v = 0;
REP(i, ing.size())
{
istringstream in(ing[i]);
int a, b;
string t1,t2;
in >> a;
while( in >> t1)
{
if(t1[t1.size()-1] == ',')
{
in >> t2;
break;
}
}
in>> b;
m += a;
v += b;
}
return v/m;
}
};
반응형