CodeForces 19A World Football Cup

Description

Everyone knows that 2010 FIFA World Cup is being held in South Africa now. By the decision of BFA (Berland's Football Association) next World Cup will be held in Berland. BFA took the decision to change some World Cup regulations:

  • the final tournament features n teams (n is always even)
  • the first n / 2 teams (according to the standings) come through to the knockout stage
  • the standings are made on the following principle: for a victory a team gets 3 points, for a draw — 1 point, for a defeat — 0 points. In the first place, teams are ordered in the standings in decreasing order of their points; in the second place — in decreasing order of the difference between scored and missed goals; in the third place — in the decreasing order of scored goals
  • it's written in Berland's Constitution that the previous regulation helps to order the teams without ambiguity.

You are asked to write a program that, by the given list of the competing teams and the results of all the matches, will find the list of teams that managed to get through to the knockout stage.

Input

The first input line contains the only integer n (1 ≤ n ≤ 50) — amount of the teams, taking part in the final tournament of World Cup. The following n lines contain the names of these teams, a name is a string of lower-case and upper-case Latin letters, its length doesn't exceed 30 characters. The following n·(n - 1) / 2 lines describe the held matches in the format name1-name2 num1:num2, wherename1name2 — names of the teams; num1num2 (0 ≤ num1, num2 ≤ 100) — amount of the goals, scored by the corresponding teams. Accuracy of the descriptions is guaranteed: there are no two team names coinciding accurate to the letters' case; there is no match, where a team plays with itself; each match is met in the descriptions only once.

Output

Output n / 2 lines — names of the teams, which managed to get through to the knockout stage in lexicographical order. Output each name in a separate line. No odd characters (including spaces) are allowed. It's guaranteed that the described regulations help to order the teams without ambiguity.

Sample Input

Input
4
A
B
C
D
A-B 1:1
A-C 2:2
A-D 1:0
B-C 1:0
B-D 0:3
C-D 0:3
Output
A
D
Input
2
a
A
a-A 2:1
Output

a

模拟足球比赛,计算出线情况。按照要求排两次序就好了。

#include<map>
#include<cmath>
#include<queue>
#include<stack>
#include<string>
#include<vector>
#include<cstdio>
#include<bitset>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
typedef long long LL;
const int low(int x){ return x&-x; }
const int INF = 0x7FFFFFFF;
const int mod = 1e9 + 7;
const int maxn = 5e2 + 10;
int T, n, x, y;
int a[maxn], b[maxn], c[maxn], ans[maxn];
char name[maxn][maxn], s1[maxn], s2[maxn], s[maxn];

bool cmp1(const int &x, const int &y)
{
	return a[x] == a[y] ? (b[x] - c[x]) == (b[y] - c[y]) ? b[x] > b[y]:(b[x] - c[x]) > (b[y] - c[y]) : a[x] > a[y];
}

bool cmp2(const int &x, const int &y)
{
	return strcmp(name[x], name[y]) < 0;
}

int main()
{
	while (scanf("%d", &n) != EOF)
	{
		map<string, int> M;
		for (int i = 1; i <= n; i++)
		{
			scanf("%s", name[i]);
			M[name[i]] = ans[i] = i;
			a[i] = b[i] = c[i] = 0;
		}
		for (int i = 1, j, k; i + i <= n*(n - 1); i++)
		{
			scanf("%s%d:%d", s, &x, &y);
			for (j = 0; s[j] != '-'; j++) s1[j] = s[j];
			s1[j++] = 0;
			for (k = j; s[k]; k++) s2[k - j] = s[k];
			s2[k - j] = 0;
			int fx = M[s1], fy = M[s2];
			b[fx] += x;	c[fx] += y;
			b[fy] += y;	c[fy] += x;
			if (x == y) a[fx]++, a[fy]++;
			else a[x > y ? fx : fy] += 3;
		}
		sort(ans + 1, ans + n + 1, cmp1);
		sort(ans + 1, ans + n / 2 + 1, cmp2);
		for (int i = 1; i + i <= n; i++) printf("%s\n", name[ans[i]]);
	}
	return 0;
}


你可能感兴趣的:(codeforces)