poj 3117(简单数学题) World Cup

来源:互联网 发布:企业淘宝费用是多少 编辑:程序博客网 时间:2024/04/28 20:19
World Cup
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 8285 Accepted: 4138

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 integersT and N, indicating respectively the number of participating teams (0 ≤T ≤ 200) and the number of played matches (0 ≤ N ≤ 10000). Each one of theT 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 byT = 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 3Brasil 3Australia 3Croacia 33 3Brasil 5Japao 1Australia 10 0

Sample Output

02

Source

South America 2006, Brazil Subregion
思路:
        设平局为X场,不是平局的为Y场,已知总场数为N,sum为总分数
        则有    X+Y=N;
                  2*X+3Y=sum;
解得:X=3*N-sum;


编程的时候一定要注意啊:N可以为0,习惯性的写成了while(scanf("%d%d",&T,&N)==2&&T&&N)   最后一直wa啊!!!
#include <iostream>#include <algorithm>#include <cstring>#include <cstdio>#include <cstdlib>#include <queue>#include <stack>#include <map>#include <vector>#include <cmath>using namespace std;int main(){    //freopen("in.txt","r",stdin);    int T,N;    while(scanf("%d%d",&T,&N)==2)    {        if(T==0&&N==0)  break;        string str;        int sum=0,goal;        for(int i=1;i<=T;i++)        {            cin>>str>>goal;            sum+=goal;        }        int ans=N*3-sum;        printf("%d\n",ans);    }    return 0;}



原创粉丝点击