World Cup
Time Limit: 1000MS | Memory Limit: 65536K |
Total Submissions: 7208 | Accepted: 3608 |
Description
A World Cup of association football is being held with teams from around the world. The standing is based on the number of points won by the teams, and the distribution of points is done the usual way. That is, when a teams wins a match, it receives 3 points; if the match ends in a draw, both teams receive 1 point; and the loser doesn’t receive any points.
Given the current standing of the teams and the number of teams participating in the World Cup, your task is to determine how many matches ended in a draw till the moment.
Input
The input contains several test cases. The first line of a test case contains two integers T and N, indicating respectively the number of participating teams (0 ≤ T ≤ 200) and the number of played matches (0 ≤ N ≤ 10000). Each one of the T lines below contains the name of the team (a string of at most 10 letter and digits), followed by a whitespace, then the number of points that the team obtained till the moment. The end of input is indicated by T = 0.
Output
For each one of the test cases, your program should print a single line containing an integer, representing the quantity of matches that ended in a draw till the moment.
Sample Input
3 3
Brasil 3
Australia 3
Croacia 3
3 3
Brasil 5
Japao 1
Australia 1
0 0
Sample Output
0
2
Source
South America 2006, Brazil Subregion
有T個球隊,N場比賽,如果赢了就得到3分,輸了沒有分,如果平局,兩個隊伍各1分,給出了T個球隊所有隊伍的最終得分,問,今年世界杯有多少個平局。
如果所有的隊伍作為一個整體,有勝負的比賽,總分+3分,如果是平局,總分+2分,是以,平局數量是:如果所有比賽均有勝負的總分減去目前總分的分值。即:3 * N - SUM。
注意點: 1)樣例有迷惑性,不是T*N-SUM(1WA)。
代碼(1AC 1WA):
#include <cstdio>
#include <cstdlib>
int main(void){
int T, N;
int i;
char name[20];
int num,sum;
while (scanf("%d%d", &T, &N), T != 0 || N != 0){
getchar();
for (i = sum = 0; i < T; i++){
scanf("%s%d", name, &num);
getchar();
sum += num;
}
printf("%d\n", 3 * N - sum);
}
return 0;
}