poj 3117 World Cup(簡単な数学の問題)


テーマリンク:http://poj.org/problem?id=3117
World Cup
Time Limit: 1000 MS
 
メモリLimit: 65536 K
Total Submissions: 8634
 
Acceepted: 4327
Description
A World Cup of assication 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 distrition of points is done the usual way.That is,when teass 3if 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 participting in the World Cup,your task is to determine how martche 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 respively the number of participting teams(0≦ T ≦200)and the number of playd matches(0≦N ≤10000).Each one of the T LINE below contains the name of the team(a string of at most 10 letter and digits)、フォローアップby a whitepace、then the number of points the team obatained till the moment.The end of input is indicated by T = 0.
Output
For each one of the test cases、your program shuld prinent a single line containing an integer、representing the quantity of matche ended 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
ソurce
South America 2006、ブラジルSubregion
サッカーの試合で引き分けとなったら、両方が1点を得ます。そうでないと、一方の3点を得て、負けた方が得点を得られません。試合のセット数tと各チームの得点状況を入力して、結果が引き分けの数を求めます。考え方:二つの方程式を作って解けばいいです。勝ち局数はXで、引き分けはYです。そうすると、総得点はsum=3 X+2 Yです。X+Y=t;解方程式組得:Y=3 t-sum;
コードは以下の通りです
#include <cstdio>
#include <iostream>
using namespace std;
int main()  
{  
    int n,t;  
	char s[17];
	int num;
	int i, j;
	int sum;
    while (scanf("%d%d",&n,&t)!=EOF)  
    {  
        if(n == 0 && t == 0)  
			break;   
		sum = 0;
		for(i = 0; i < n; i++)
		{
            cin>>s>>num;  
            sum += num;  
        }  
		int ans = 3*t - sum;
        printf("%d
",ans); } return 0; }