pku 2272 Bullseye

http://acm.pku.edu.cn/JudgeOnline/problem?id=2272

题意是求两射击员的得分,然后比较谁胜利了。

#include <stdio.h>
#include <math.h>

int distance(double x,double y)//计算得分的函数
{
	
	double dis;
	dis = sqrt(x*x + y*y);//计算半径
	if(dis <= 3)
		return 100;
	else if(dis <= 6)
		return 80;
	else if(dis <= 9)
		return 60;
	else if(dis <= 12)
		return 40;
	else if(dis <= 15)
		return 20;
	else 
		return 0;
}

void Work()
{
	double a,b;
	int i,j,flag;
	int score[2];
	while(1)
	{
		flag = 0;
		for(i = 0;i < 2;i ++)
		{
			score[i] = 0;
			for(j = 0;j < 3;j ++)
			{
				scanf("%lf%lf",&a,&b);
				if(a == -100)
				{
					flag = 1;
					break;
				}
				score[i] = score[i] + distance(a,b);//分数累加
			}
			if(flag)
				break;
		}
		//比较分数
		if(flag)
			break;
		if(score[0] == score[1])
			printf("SCORE: %d to %d, TIE./n",score[0],score[1]);
		else if(score[0] < score[1])
			printf("SCORE: %d to %d, PLAYER 2 WINS./n",score[0],score[1]);
		else if(score[0] > score[1])
			printf("SCORE: %d to %d, PLAYER 1 WINS./n",score[0],score[1]);
	}
}

int main()
{
	Work();
	return 0;
}
 
/*
-9 0 0 -4.5 -2 2 9 0 0 4.5 2 -2
-19.0 19.0 0 0 0 0 3 3 6 6 12 12
-100 0 0 0 0 0 0 0 0 0 0 0
SCORE: 240 to 240, TIE.
SCORE: 200 to 140, PLAYER 1 WINS.
*/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值