TJU Problem 2101 Bullseye

注意代码中:

  result1 << " to " << result2 << ", PLAYER 1 WINS."<< endl;

  result1 << " to " << result2 << ", PLAYER 1 WINS. "<< endl;

虽然只在WINS后只差一个空格,但会导致PE。

原题:

2101.   Bullseye


Time Limit: 1.0 Seconds   Memory Limit: 65536K
Total Runs: 3848   Accepted Runs: 1306



Problem

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
partially 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: r2 = x2 + y2 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.

Source: Greater New York
2004

源代码:

 1 #include <iostream>
 2 #include <string.h>
 3 const int maxn = 15;
 4 using namespace std;
 5
 6 double score[maxn];
 7
 8 int sCount (double i, double j)    {
 9     double temp = i*i + j*j;
10     if (temp <= 9)    return 100;
11     else if (temp <= 36 && temp > 9)    return 80;
12     else if (temp <= 81 && temp > 36)    return 60;
13     else if (temp <= 144 && temp > 81)    return 40;
14     else if (temp <= 225 && temp > 144)    return 20;
15     else return 0;
16 }
17 int main()
18 {
19     memset(score, 0, sizeof(score));
20     while (cin >> score[0] && score[0] != -100)    {
21         for (int i = 1; i < 12; i++)    {
22             cin >> score[i];
23         }
24         int result1 = 0, result2 = 0;
25         result1 += sCount(score[0], score[1]) + sCount(score[2], score[3])
26             + sCount(score[4], score[5]);
27         result2 += sCount(score[6], score[7]) + sCount(score[8], score[9])
28             + sCount(score[10],score[11]);
29         if (result1 > result2)    cout << "SCORE: "<<
30              result1 << " to " << result2 << ", PLAYER 1 WINS."<< endl;
31         else if (result2 > result1)    cout << "SCORE: "<<
32              result1 << " to " << result2 << ", PLAYER 2 WINS."<< endl;
33         else    cout << "SCORE: "<< result1 << " to " << result2 << ", TIE." << endl;
34     }
35     return 0;
36 }
时间: 2024-10-10 22:44:42

TJU Problem 2101 Bullseye的相关文章

TJU Problem 1065 Factorial

注意数据范围,十位数以上就可以考虑long long 了,断点调试也十分重要. 原题: 1065.   Factorial Time Limit: 1.0 Seconds   Memory Limit: 65536KTotal Runs: 6067   Accepted Runs: 2679 The most important part of a GSM network is so called Base Transceiver Station (BTS). These transceiver

TJU Problem 2520 Quicksum

注意: for (int i = 1; i <= aaa.length(); i++) 其中是“ i <= ",注意等号. 原题: 2520.   Quicksum Time Limit: 0.5 Seconds   Memory Limit: 65536KTotal Runs: 2964   Accepted Runs: 1970 A checksum is an algorithm that scans a packet of data and returns a single

TJU Problem 1015 Gridland

最重要的是找规律. 下面是引用 http://blog.sina.com.cn/s/blog_4dc813b20100snyv.html 的讲解: 1 做这题时,千万不要被那个图给吓着了,其实这题就是道简单的数学题. 2 3 首先看当m或n中有一个为2的情况,显然,只需要算周长就OK了.即(m+n-2)*2,考虑到至少其中一个为2,所以答案为2 *m或2*n,亦即m*n.注意这里保证了其中一个数位偶数. 4 当m,n≥3时,考虑至少其中一个为偶数的情况,显然,这种情况很简单,可以得出,结果为m*

TJU Problem 2857 Digit Sorting

原题: 2857.   Digit Sorting Time Limit: 1.0 Seconds   Memory Limit: 65536KTotal Runs: 3234   Accepted Runs: 1704 Several players play a game. Each player chooses a certain number, writes it down (in decimal notation, without leading zeroes) and sorts t

TJU Problem 1100 Pi

注: 1. 对于double计算,一定要小心,必要时把与double计算相关的所有都变成double型. 2. for (int i = 0; i < N; i++)         //N 不可写为N - 1,否则当N为1时无法进行: 原题: 1100.   Pi Time Limit: 1.0 Seconds   Memory Limit: 65536KTotal Runs: 5683   Accepted Runs: 2317 Professor Robert A. J. Matthews

TJU Problem 2548 Celebrity jeopardy

下次不要被长题目吓到,其实不一定难. 先看输入输出,再揣测题意. 原文: 2548.   Celebrity jeopardy Time Limit: 1.0 Seconds   Memory Limit: 65536KTotal Runs: 1306   Accepted Runs: 898 It's hard to construct a problem that's so easy that everyone will get it, yet still difficult enough

【水】TJU Problem 1805 Electrical Outlets

没看懂题,直接看了INPUT,原来真的可以猜出来. 原题: 1805.   Electrical Outlets Time Limit: 1.0 Seconds   Memory Limit: 65536KTotal Runs: 3321   Accepted Runs: 2575 Roy has just moved into a new apartment. Well, actually the apartment itself is not very new, even dating ba

TJU Problem 1644 Reverse Text

注意: int N; cin >> N; cin.ignore(); 同于 int N; scanf("%d\n",&N); 另:关于 cin 与 scanf: scanf是格式化输入,printf是格式化输出. cin是输入流,cout是输出流.效率稍低,但书写简便. 格式化输出效率比较高,但是写代码麻烦. 流输出操作效率稍低,但书写简便. cout之所以效率低,正如一楼所说,是先把要输出的东西存入缓冲区,再输出,导致效率降低. 缓冲区比较抽象,举个例子吧: 曾经

TJU Problem 1090 City hall

注:对于每一横行的数据读取,一定小心不要用int型,而应该是char型或string型. 原题: 1090.   City hall Time Limit: 1.0 Seconds   Memory Limit: 65536KTotal Runs: 4874   Accepted Runs: 2395 Because of its age, the City Hall has suffered damage to one of its walls. A matrix with M rows an