poj 3117 World Cup(简单数学题)

题目链接:http://poj.org/problem?id=3117

World Cup

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 8634   Accepted: 4327

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

题意:一场足球赛中,如果双方打成了平手,那么双方各得一分,否则,赢得一方的3分,输得一方不得分。输入比赛的局数t和各队的得分情况,求出结果为平局的数量。

思路:列两个方程解一下即可,我们可以设赢得局数为X,平局为Y,那么总得分sum = 3X+2Y;且X+Y=t;

解方程组得:Y = 3t-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\n",ans);
    }
    return 0;
}

poj 3117 World Cup(简单数学题),布布扣,bubuko.com

时间: 2024-10-20 03:11:51

poj 3117 World Cup(简单数学题)的相关文章

Poj 3117 World Cup

1.Link: http://poj.org/problem?id=3117 2.Content: World Cup Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8778   Accepted: 4406 Description A World Cup of association football is being held with teams from around the world. The standin

POJ 3071 Football(简单 概率DP)

Football 原文链接:http://blog.csdn.net/xuechelingxiao/article/details/38520105 大意:2^n 个球队进行单场淘汰赛,每两只球队之间比赛会有胜负的概率,问最后谁夺冠的概率最大. 思路:简单的概率DP问题,主要是怎么处理哪两个球队比赛的问题. DP方程为 dp[i][j] = ∑(dp[i-1][j]*dp[i-1][k]*p[j][k]); //dp[i][j]表示第 i 轮的时候,第 j 支队伍赢的概率.. 对于其中位运算,可

Codeforces Round #262 (Div. 2)460A. Vasya and Socks(简单数学题)

题目链接:http://codeforces.com/contest/460/problem/A A. Vasya and Socks time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasya has n pairs of socks. In the morning of each day Vasya has to put o

hdu 2368 Alfredo&#39;s Pizza Restaurant(简单数学题)

转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2368 题目很简单,但是比较恶心,用sqrt WA到死也不过,不用秒过: 忍不住吐槽一下; Problem Description Traditionally after the Local Contest, judges and contestants go to their favourite restaurant,

poj 3077 Rounders 【简单字符串处理】

题意:就是4舍5入到最近的数. 题意有些难理解... 代码: #include <stdio.h> #include <string.h> char s[10]; int main() { int t, n; scanf("%d", &t); while(t --){ memset(s, 0, sizeof(s)); scanf("%s", s); int len = strlen(s); if(len == 1){ printf(&

POJ 3982 序列(JAVA,简单,大数)

题目 //在主类中 main 方法必须是 public static void 的,在 main 中调用非static类时会有警告信息, //可以先建立对象,然后通过对象调用方法: import java.io.*; import java.util.*; import java.math.*; public class Main { /** * @xqq */ public BigInteger a99(BigInteger a, BigInteger b, BigInteger c) { f

hdu2374 A Game with Marbles(简单数学题)

转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2374 Problem Description There are n bowls, numbered from 1 to n. Initially, bowl i contains mi marbles. One game step consists of removing one marble from a bowl.

poj 3117 Friends or Enemies?(模拟)

题目链接:http://poj.org/problem?id=3119 Friends or Enemies? Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 431   Accepted: 177 Description A determined army on a certain border decided to enumerate the coordinates in its patrol in a way to

poj 3273 Monthly Expence 简单二分

1 /** 2 大意: 有连续的n天,每一天有一定的花费,将其分成m份,每一份占一天或者连续的几天,求这m份中的最大值 3 思路: 二分其最大上限,看在此最大上线,能分成多少份,若大于m份,说明上限过小,需要扩大上限 4 若小于m份,则说明,下限过大,需要缩小上限. 5 **/ 6 #include <iostream> 7 8 using namespace std; 9 int c[100010]; // 记录,每天的花费 10 int main() 11 { 12 int n,m; 13