2009-01-19
SRM364 Div1 Easy: Paintball
300点問題。
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define rep(var,n) for(int var=0;var<(n);var++)
#define found(s,e) ((s).find(e)!=(s).end())
bool GreaterTeam(const pair<string,int>& t1, const pair<string,int>& t2){
if(t1.second > t2.second) return true;
if(t1.second < t2.second) return false;
if(t1.first <= t2.first) return true;
return false;
}
class Paintball {
public:
vector<string> getLeaderboard(vector<string> players, vector<string> messages) {
map<string,int> teams;
map<string,string> player_team;
map<string,int> player_point;
tr(players,it){
vector<string> s=split(*it);
player_team[s[0]] = s[1];
player_point[s[0]] = 0;
teams[s[1]]=0;
}
tr(messages,it){
vector<string> s=split(*it);
string p1=s[0], p2=s[2];
if(p1==p2){
player_point[p1]--;
}else{
string t1=player_team[p1], t2=player_team[p2];
if(t1==t2){
player_point[p1]--;
}else{
player_point[p1]++;
player_point[p2]--;
}
}
}
tr(player_point,it){
string p=it->first;
string t=player_team[p];
teams[t] += player_point[p];
}
vector<pair<string,int> > ts(all(teams));
sort(all(ts),GreaterTeam);
vector<string> res;
tr(ts,it){
stringstream ss;
ss << it->first << " " << it->second;
res.pb(ss.str());
vector<pair<string,int> > ps;
tr(player_team,jt){
if(jt->second == it->first){
ps.pb(make_pair(jt->first,player_point[jt->first]));
}
}
sort(all(ps),GreaterTeam);
tr(ps,jt){
stringstream ss2;
ss2 << " " << jt->first << " " << jt->second;
res.pb(ss2.str());
}
}
return res;
}
};
もう一度書いた。11分。
変数名をうまく付けないと訳がわからなくなる。
今回は比較関数なし。
class Paintball {
public:
vector<string> getLeaderboard(vector<string> players, vector<string> messages) {
map<string,int> ppoint,tpoint;
map<string,string> team;
tr(players,it){
vector<string> s=split(*it);
string p=s[0], t=s[1];
team[p]=t;
ppoint[p]=tpoint[t]=0;
}
tr(messages,it){
vector<string> s=split(*it);
string p1=s[0], p2=s[2];
string t1=team[p1], t2=team[p2];
if(p1==p2){
ppoint[p1]--;
tpoint[t1]--;
}else{
if(t1==t2){
ppoint[p1]--;
tpoint[t1]--;
}else{
ppoint[p1]++;
tpoint[t1]++;
ppoint[p2]--;
tpoint[t2]--;
}
}
}
vector<pair<int,string> > tx;
tr(tpoint,it) tx.pb(make_pair(-it->second,it->first));
sort(all(tx));
vector<string> res;
tr(tx,it){
stringstream sst;
sst << it->second << " " << -(it->first);
res.pb(sst.str());
vector<pair<int,string> > px;
tr(team,jt) if(jt->second==it->second) px.pb(make_pair(-ppoint[jt->first],jt->first));
sort(all(px));
tr(px,jt){
stringstream ssp;
ssp << " " << jt->second << " " << -(jt->first);
res.pb(ssp.str());
}
}
return res;
}
};
コメント
トラックバック - https://topcoder-g-hatena-ne-jp.jag-icpc.org/n4_t/20090119