G - I Think I Need a Houseboat(简单题,粘贴下来是因为数据精度需要注意)

These will be floating point numbers;看这句话,就是说数据会是浮点型的,

问题(一)数据定义成double类型就过了

我当时以为定义成float类型就可以了,

因为题上说是float point number,但是定义成float类型的却wrong answer,同学让我改成double类型的,我当时问她依据

她说没有依据,你试试呗,我挺固执地继续从别的地方找错误,没有依据?不可能嘛!最后无奈试了一下果真改了类型就对了,

得出一个教训,题上让用的floating point numbers时候,你可以用double类型的数据存储,用不上那么长最后不用后边多余的位数就是了嘛

问题(二)小数点后面有精确到7位才过,8位就不过

还发现一个问题,存储PI的double类型数据,我定义成3.1415926就对了,定义成3.14159265就错了,

可能是后台测评的时候用的PI就是3.1415926,但是我觉得也可以从题中找,题中说是floating point numbers

我想意思就是定义精度为7~8位的数据就可以了,因为float精度7~8位,

ps:我想了下,这道题给出的数据精度7~8位但是算的时候必须定义成double类型的原因是S = PI * R^2;这样一来,

数据就会扩大很多,如果仍然用float类型存,就会丢失精度

Description

Fred Mapper is considering purchasing some land in Louisiana to build his house on. In the process of investigating the land, he learned that the state of Louisiana is actually shrinking by 50 square miles each year, due to erosion caused by the Mississippi River. Since Fred is hoping to live in this house the rest of his life, he needs to know if his land is going to be lost to erosion.

After doing more research, Fred has learned that the land that is being lost forms a semicircle. This semicircle is part of a circle centered at (0,0), with the line that bisects the circle being the X axis. Locations below the X axis are in the water. The semicircle has an area of 0 at the beginning of year 1. (Semicircle illustrated in the Figure.)

Input

The first line of input will be a positive integer indicating how many data sets will be included (N).

Each of the next N lines will contain the X and Y Cartesian coordinates of the land Fred is considering. These will be floating point numbers measured in miles. The Y coordinate will be non-negative. (0,0) will not be given.

Output

For each data set, a single line of output should appear. This line should take the form of:

“Property N: This property will begin eroding in year Z.”

Where N is the data set (counting from 1), and Z is the first year (start from 1) this property will be within the semicircle AT THE END OF YEAR Z. Z must be an integer.

After the last data set, this should print out “END OF OUTPUT.”

Notes:

1. No property will appear exactly on the semicircle boundary: it will either be inside or outside.

2. This problem will be judged automatically. Your answer must match exactly, including the capitalization, punctuation, and white-space. This includes the periods at the ends of the lines.

3. All locations are given in miles.

Sample Input

2
1.0 1.0
25.0 0.0

Sample Output

Property 1: This property will begin eroding in year 1.
Property 2: This property will begin eroding in year 20.
END OF OUTPUT.

题目来源

代码:

#include <stdio.h>
int main()
{
    int n, case_num = 1;
    double x, y;
    int t;
    scanf("%d", &n);
    while(n--)
    {
        scanf("%lf%lf", &x, &y);
        double S = 3.1415926*(x*x + y*y)/2.0;
        t = (S / 50.0) + 1;
        printf("Property %d: This property will begin eroding in year %d.\n", case_num++, t);
    }
    printf("END OF OUTPUT.\n");
    return 0;
}
时间: 2024-10-18 07:56:32

G - I Think I Need a Houseboat(简单题,粘贴下来是因为数据精度需要注意)的相关文章

(hdu 简单题 128道)AC Me(统计一行文本中各个字母出现的次数)

题目: AC Me Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 13465    Accepted Submission(s): 5927 Problem Description Ignatius is doing his homework now. The teacher gives him some articles and as

hdu4847 Wow! Such Doge!(简单题+坑爹的输入)

转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4847 --------------------------------------------------------------------------------------------------------------------------------------------

uva Fire Station(FLODY+枚举)(挺不错的简单题)

消防站 题目链接:Click Here~ 题意分析: 就是给你f个消防站,n个路口.要你求出在已有消防站的基础上在n个路口的哪个路口上在建立一个消防站,使得n个路口的到离自己最近的消防站最近的距离中最大的一个值最小.即:求n个最近路口中最大的一个,使其改最大值最小.详细的要求自己看题目吧~ 算法分析: 因为,是n个路口到每个消防站的距离.所以,我们可以想到先用一次Flody算法.把每两点的最近距离给算出来.之后在枚举N个路口,进行判断比较得出答案. #include <iostream> #i

poj3041(二分匹配简单题)

题目链接:http://poj.org/problem?id=3041 Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14022   Accepted: 7629 Description Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape of an N x N grid (1 <

poj2105 IP Address(简单题)

题目链接:http://poj.org/problem?id=2105 Description Suppose you are reading byte streams from any device, representing IP addresses. Your task is to convert a 32 characters long sequence of '1s' and '0s' (bits) to a dotted decimal format. A dotted decima

poj 3270 Cow Sorting 置换群 简单题

假设初始状态为 a:2 3 1 5 4 6 则目标状态为 b:1 2 3 4 5 6且下标为初始状态中的3 1 2 4 5 6(a[3],a[1]...) 将置换群写成循环的形式 (2,3,1),(5,4),6就不用移动了. 移动方式2种 1:选循环内最小的数和其他len-1个数交换 2:选整个序列最小的数和循环内最小的数交换,转到1,再换回来. #include<cstdio> #include<queue> #include<algorithm> #include&

数论 --- 简单题

吃糖果 Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 22376    Accepted Submission(s): 6396 Problem Description HOHO, 终于从Speakless手上赢走了所有的糖果,是Gardon吃糖果时有个特殊的癖好,就是不喜欢将一样的糖果放在一起吃,喜欢先吃一种,下一次吃另一 种,这样:

BZOJ 2683 简单题 ——CDQ分治

简单题 #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define F(i,j,k) for (int i=j;i<=k;++i) #define D(i,j,k) for (int i=j;i>=k;--i) #define maxn 2000005 int sum[maxn]; void a

HNU 12868 Island (简单题)

题目链接:http://acm.hnu.cn/online/?action=problem&type=show&id=12868&courseid=272 解题报告:输入n*m的地图,+表示土地,-表示水,要你求这个海岛的海岸线有多长,扫一遍就可以了. 1 #include<cstdio> 2 const int maxn = 2000; 3 char map[maxn][maxn]; 4 int _x[4] = {-1,0,1,0}; 5 int _y[4] = {0