N - Bullseye-程序员宅基地

技术标签: acm  

A simple dartboard consists of a flat, circular piece of cork with concentric rings drawn on it. Darts are thrown at the board by players in an attempt to hit the center of the dartboard (the Bullseye). The region between each pair of rings (or the center and the first ring) represents a certain point value. The closer the region is to the center of the dartboard, the more points the region is worth, as shown in the diagram below:

Ring radii are at 3", 6", 9", 12" and 15" (the Bullseye has a diameter of 6"). A game of Simple Darts between two players is played as follows. The first player throws 3 darts at the board. A score is computed by adding up the point values of each region that a dart lands in. The darts are removed. The second player throws 3 darts at the board; the score for player two is computed the same way as it is for player one. The player with the higher score wins.

For this problem, you are to write a program that computes the scores for two players, and determine who, if anyone, wins the game. If a dart lands exactly on a ring (region boundary), the higher point value is awarded. Any dart outside the outer ring receives no points. For the purposes of this problem, you can assume that a dart has an infinitely fine point and can not land paritially on a ring; it is either on the ring or it is not on the ring. Standard double precision floating point operations will be should be used.

Input
Input consists of 1 or more datasets. A dataset is a line with 12 double-precision values separated by spaces. Each pair of values represents the X and Y distances respectively of a dart from the center of the board in inches. (the center is located at X = 0, Y = 0. The range of values are: -20.0<=X, Y<=20.0. Player one's darts are represented by the first 3 pairs of values, and player two's by the last 3 pairs of values. Input is terminated by the first value of a dataset being -100.
Output
For each dataset, print a line of the form:
SCORE: N to M, PLAYER P WINS. 

Or:
SCORE: N to M, TIE. 

N is player one's score, and M is player two's score. P is either 1 or 2 depending on which player wins. All values are non-negative integers.

Formula

Recall: r 2 = x 2 + y 2 where r is the radius, and (x, y) are the coordinates of a point on the circle.
Sample Input
-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
Sample Output
SCORE: 240 to 240, TIE.
SCORE: 200 to 140, PLAYER 1 WINS.

终于遇到一题简单的了!!题意:两个人打靶比赛,靶子各个圆半径为3,6,9,12,15。命中得分多少图可以看出来。每行输入12个数字即6对(x,y),前三组是1号,后两组是2号,总分谁高就输出:SCORE: N to M, PLAYER P WINS. 打平时就 :SCORE: N to M, TIE. 用圆的公式即可的,一开始想用数组存12个数字,但后来想想不需要。中间的问题:打完之后,输入数据后直接死循环输出,后来发现是因为求总和时没有用double定义。

#include<iostream>
using namespace std;
int judge(int a,double b,double c);
void output(int a,int b);
int main()
{
 double n,m;
 int flag=1;
 int i,j,k;
 double x,y;
 while(1)
 {
  n=0;m=0;
   for(i=0;i<2;i++)//0表示1号,1表示2号
   {
    for(j=0;j<3;j++)
    {
     cin>>x;
     cin>>y;
     if(i==0&&j==0&&x==-100)//等于-100时就结束。
     {
      flag=0;
     }
     if(i==0)
     {
      n=judge(n,x,y);
     }
     else
     {
      m=judge(m,x,y);
     }
    }
   }
   if(flag==0)
   {
    return 0;
   }
   output(n,m);
 }
}
int judge(int a,double b,double c)
{
 double sum;
 sum=b*b+c*c;
 if(sum<=9)
 {
  return a+100;
 }
 else if(sum>9&&sum<=36)
 {
  return a+80;
 }
 else if(sum>36&&sum<=81)
 {
  return a+60;
 }
 else if(sum>81&&sum<=144)
 {
  return a+40;
 }
 else if(sum>144&&sum<=225)
 {
  return a+20;
 }
 return a;
}
void output(int a,int b)
{
 if(a==b)
 {
  cout<<"SCORE: "<<a<<" to "<<b<<", TIE."<<endl;
 }
 else if(a<b)
 {
  cout<<"SCORE: "<<a<<" to "<<b<<", PLAYER "<<2<<" WINS."<<endl;
 }
 else
 {
  cout<<"SCORE: "<<a<<" to "<<b<<", PLAYER "<<1<<" WINS."<<endl;
 }
}

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/whhhzs/article/details/79123581

智能推荐

Python 安全编程学习总结_python you must specify a valid interface name.-程序员宅基地

文章浏览阅读6.3k次,点赞2次,收藏15次。Python黑帽编程-ARP之一http://blog.csdn.net/supercooly/article/details/53956494参考文章:https://zhuanlan.zhihu.com/p/24645819参考文章:http://bbs.ichunqiu.com/thread-13429-1-1.html一、ARP协议中文名称:地址解析协议_python you must specify a valid interface name.

【solo】环境配置_深度学习solo算法必须要安装mmcv吗-程序员宅基地

文章浏览阅读329次。此帖记录一下SOLO环境配置的过程以及一些问题和解决办法。_深度学习solo算法必须要安装mmcv吗

模板与泛型编程_模版是复用代码的一中机制,利用模版可以进行与类型无关的程序设计-程序员宅基地

文章浏览阅读239次。泛型编程:编写与类型无关的通用代码,是代码复用的一种手段。模板是泛型编程的基础。函数模板代表了一个函数家族,该函数模板与类型无关,在使用时被参数化,根据实参类型产生函数的特定类型版本。模板的格式template<typename T1, typename T2,…,typename Tn>返回值类型 函数名(参数列表){}模板分为类模板和函数模板模板它本身并不是函数,是编译..._模版是复用代码的一中机制,利用模版可以进行与类型无关的程序设计

如何将访问的接口去掉token验证_不通微服务开发阶段怎样取消sa_token验证-程序员宅基地

文章浏览阅读9.9k次。如何将访问的接口去掉token验证项目应用:springboot oath2完成此操作需要修改两个模块的application.yml文件修改,一个是getway网关的yml文件,另一个则是接口所在模块的yml文件_不通微服务开发阶段怎样取消sa_token验证

解决SVN Can’t open file ‘/XXX/xxx/db/txn-current-lock’错误_svn cant open file-程序员宅基地

文章浏览阅读1.8w次。今天用非root账号,用sudo 命令 添加了两个账号,然后重启服务···可以正常取出东西,但是不能提交···报的错就是 : 不能打开文件“/var/svn/svnrepos/db/txn-current-lock”: 权限不够查了半天 找到了解决办法,原文链接:http://blog.sina.com.cn/s/blog_7139569d0100woar.htm_svn cant open file

Microsoft Visual Studio 2019正式版离线安装包下载_microsoft vcredist 2019-程序员宅基地

文章浏览阅读2.4w次,点赞11次,收藏44次。原文地址:https://www.bitecho.net/microsoft-visual-studio-2019.html#respondVisual Studio(简称VS)是微软公司的开发工具包系列产品,包括了整个软件生命周期中所需要的大部分工具,如UML工具、代码管控工具、集成开发环境(IDE)等等,并且几乎适用于所有开发平台。微软于4月3日正式发布了Visual Studio 2019正式版,在IDE、性能、常规调试、源控制和Team管理器、编程语言、Web技术、Xamarin移动..._microsoft vcredist 2019

随便推点

深度学习目标检测系列之YOLO9000_yolov9-程序员宅基地

文章浏览阅读2.7k次,点赞6次,收藏6次。1.闲言 在正式的学习之前,我喜欢先放飞一下自我。我觉得技术就是用来聊的,找个酒馆,找些大神,咱们听着音乐一起聊起来。所以我特别希望能把自己的微博写的口语化,就像玩一样。就像古代那些说书人一样,萧远山和慕容博相视一笑,王图霸业,血海深仇,尽归尘土。这是我向往的一种表达方式,但是我现在还达不到那个境界,只能尽力而为吧。2.YOLOV2 1.十个改造点 yolov1提升了目标检测的速度,但是在MAP方面却掉了上去。所以说铁打的大神,流水的模型..._yolov9

自学微信二次开发(1)_微信 电脑端 二次开发-程序员宅基地

文章浏览阅读1.1w次,点赞8次,收藏5次。在二次开发微信,首先要成为微信开发者,在微信开发者平台注册,还要注册一个微信公众号,注册过程很简单,唯一的要求就是要绑定银行卡的微信账号扫一下二维码.然后就能注册成功微信公众号了. 在注册微信公众号之后有两种模式,一个是编辑模式,还有一个就是开发者模式.编辑模式其实也是一个后台操作的过程,在编辑模式下基本上一些基本的功能都能实现,像关键字回复,被关注的时候回复,还有订阅号每天能够推送一条信息给关注_微信 电脑端 二次开发

测试用例集构建_第2部分。为生产前测试构建测试用例-程序员宅基地

文章浏览阅读456次。管理生产的操作要求 内容系列: 此内容是#在系列的一部分#: 管理生产操作要求 https://www.ibm.com/developerworks/library/?series_title_by=manage+operational+requirements+for+production 请继续关注本系列中的其他内容。 该内容是该系列的一部分: 管理生产的操作需..._构建测评用例

Android 获取当前日期 时间很方便 直接调用Calendar类即可-程序员宅基地

文章浏览阅读282次。Android 获取当前日期 时间很方便 直接调用Calendar类即可定义变量private int mHour; private int mMinute; private int mYear; private int mMonth; private int mDay;调用如下 final Calendar c..._直接调用calendar类年份

leetcode 16 最接近的三数之和_最接近的三数之和 时间复杂度-程序员宅基地

文章浏览阅读145次。据说这个题很容易考,嘻嘻嘻,我自己做做。。。每做一个题 它还有变形,我又要开始思考。。。。。所有算法题里面我最讨厌 矩阵 矩阵,数学都没有搞明白矩阵,你还要我写代码。。。说明我今年变聪明了。。。。我做题都是非常简单思路,大道至简。就是如果这三个数之和刚好与target相等就直接输出,如果不是 就看范围。找到距离这个target最近的两个数。min,max最后用绝对值比较一下就可以了..._最接近的三数之和 时间复杂度

理解傅里叶变换算法(一)_求序列的5点dft-程序员宅基地

文章浏览阅读710次。经典算法研究系列:十、从头到尾彻底理解傅里叶变换算法、上作者:July、dznlong 二零一一年二月二十日推荐阅读:The Scientist and Engineer's Guide to Digital Signal Processing,By Steven W. Smith, Ph.D。此书地址:http://www.dspguide.com/pdfbook.htm_求序列的5点dft

推荐文章

热门文章

相关标签