您的位置:首页 > 其它

hdu 1225大水题

2013-06-01 00:36 357 查看
/*
* hdu1225/win.cpp
* Created on: 2013-5-31
* Author    : ben
*/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <functional>
#include <numeric>
#include <cctype>
using namespace std;
#ifndef ONLINE_JUDGE
const int MAXN = 60;
#else
const int MAXN = 6000;
#endif
typedef struct Person {
char name[40];
int win;
int lost;
int score;
}Person;

Person persons[MAXN];
map<string, int> mymap;
int pn;

inline int getNameId(const char *str) {
string temp(str);
if(mymap.count(temp) > 0) {
return mymap[temp];
}
strcpy(persons[pn].name, str);
mymap[temp] = pn;
return pn++;
}

inline bool operator<(const Person& p1, const Person& p2) {
if(p1.score != p2.score) {
return p1.score > p2.score;
}
if(p1.win - p1.lost != p2.win - p2.lost) {
return p1.win - p1.lost > p2.win - p2.lost;
}
if(p1.win != p2.win) {
return p1.win > p2.win;
}
return string(p1.name) < string(p2.name);
}

int main() {
#ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
#endif
char name1[40], name2[40];
int N, n, a, b;
while(scanf("%d", &n) == 1) {
memset(persons, 0, sizeof(persons));
mymap.clear();
N = n * (n - 1);
pn = 0;
while(N--) {
scanf(" %s VS %s %d:%d", name1, name2, &a, &b);
int i = getNameId(name1);
int j = getNameId(name2);
persons[i].win += a;
persons[i].lost += b;
persons[j].win += b;
persons[j].lost += a;
if(a > b) {
persons[i].score += 3;
}else if(a < b) {
persons[j].score += 3;
}else {
persons[i].score++;
persons[j].score++;
}
}
sort(persons, persons + n);
for(int i = 0; i < n; i++) {
printf("%s %d\n", persons[i].name, persons[i].score);
}
putchar('\n');
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: