poj 3117 World Cup

简介:
 

题目大意很简单:一场足球赛中,若果双方平手的话,那么双方各得一分,否则,赢的一方得3分,输的一方不得分。输入比赛的数量t和各队的得分,求出结果为平局的比赛的数量。其实这是一道很简单的数学题,就是解二元一次方程组。先求出各队得分的总和sum,设不是平局的数量为X,平局的数量为Y,则可得方程组:

3X + 2Y = sum;X + Y = t(t为比赛的总数量)解之得:Y = 3t - sum

我居然开始还想错了,用  printf("%d\n",t*n-totscore);  这说明好脑子不如烂笔头,什么都还是动手自己算算保险

正确代码如下

#include <stdio.h>

int main()
{
	int t,n,i;
	char name[15];
	int tmp,totscore;
	
	while(scanf("%d%d",&t,&n))
	{
		if(t==0)
			break;
		
		totscore=0;			//总分清零
		
		for(i=0;i<t;i++)
		{
			scanf("%s",name);
			scanf("%d",&tmp);
			
			totscore+=tmp;
		}
		
		printf("%d\n",3*n-totscore);
	}
	
	return 0;
}


相关文章
|
10月前
|
网络架构
POJ 3250 Bad Hair Day、POJ 2796 Feel Good(单调栈)
POJ 3250 Bad Hair Day、POJ 2796 Feel Good(单调栈)
|
C++
【PAT甲级 - C++题解】1011 World Cup Betting
【PAT甲级 - C++题解】1011 World Cup Betting
42 0
【1011】World Cup Betting (20 分)
【1011】World Cup Betting (20 分) 【1011】World Cup Betting (20 分)
80 0
|
机器学习/深度学习
POJ 1775 (ZOJ 2358) Sum of Factorials
POJ 1775 (ZOJ 2358) Sum of Factorials
127 0
1011. World Cup Betting (20)
简析:关键是W T L的对应。 #include using namespace std; int main(int argc, const char * argv[]) { char c1 = '\0', c...
671 0
|
机器学习/深度学习 人工智能
洛谷 P1200 [USACO1.1]你的飞碟在这儿Your Ride Is He…【字符串+模拟】
P1200 [USACO1.1]你的飞碟在这儿Your Ride Is He… 题目描述 众所周知,在每一个彗星后都有一只UFO。这些UFO时常来收集地球上的忠诚支持者。不幸的是,他们的飞碟每次出行都只能带上一组支持者。
1594 0
|
人工智能 机器学习/深度学习
POJ 1775 (ZOJ 2358) Sum of Factorials
Description John von Neumann, b. Dec. 28, 1903, d. Feb. 8, 1957, was a Hungarian-American mathematician who made important contributions t...
1124 0