G - Bullseye

Description

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.


这道题十分简单,但我的代码提交上去总是submit failed,可能是网不太好的原因,总是提交错误!!!我很生气!!!!!
但是我提交别人的代码就可以提交成功,应该是代码本身的缺陷吧,以下是我的代码
#include <iostream>
using namespace std;
int f(double x,double y)
{
    double j=x*x+y*y;
        if(j<=9)return 100;
        else if(j<=36)return 80;
        else if(j<=81)return 60;
        else if(j<=144)return 0;
        else if(j<=225)return 20;
        else return 0;
}
int main()
{
    int i,x,y;
    while(1){
        double a[15];
        for(i=0;i<12;i++)cin>>a[i];
        if(a[0]==-100)break;
        x=0;
        y=0;
        for(i=0;i<5;i+=2)x+=f(a[i],a[i+1]);
        for(i=6;i<11;i+=2)y+=f(a[i],a[i+1]);
        cout<<"SCORE: "<<x<<" to "<<y<<", ";
        if(x==y)cout<<"TIE."<<endl;
        if(x>y)cout<<"PLAYER 1 WINS."<<endl;
        if(x<y)cout<<"PLAYER 2 WINS."<<endl;
    }
    //system("pause");
    return 0;
}


下面是提交成功的别人的代码

#include <iostream>
using namespace std;
int f(double x,double y)
{
    double j=x*x+y*y;
        if(j<=9)return 100;
        else if(j<=36)return 80;
        else if(j<=81)return 60;
        else if(j<=144)return 40;
        else if(j<=225)return 20;
        else return 0;
}
int main()
{
    int x,y;
    double a,b;
    while(cin>>a){
        if(a==-100)break;
        x=0;
        y=0;
        cin>>b;
        x+=f(a,b);
        for(int i=0;i<2;i++){
            cin>>a>>b;
            x+=f(a,b);
        }
        for(int i=0;i<3;i++){
            cin>>a>>b;
            y+=f(a,b);
        }
        cout<<"SCORE: "<<x<<" to "<<y<<", ";
        if(x==y)cout<<"TIE."<<endl;
        if(x>y)cout<<"PLAYER 1 WINS."<<endl;
        if(x<y)cout<<"PLAYER 2 WINS."<<endl;
    }
    //system("pause");
    return 0;
}

也许是思路的大不同,我的代码没有真正的按照计算机的思路来,所以hdu无法接受我的代码,愁死了!!!!

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值