I Think I Need a Houseboat问题

Time Limit: 1000MS

Memory Limit: 10000K

Total Submissions: 107313

Accepted: 46580

FredMapper is considering purchasing some land in Louisiana to build his house on.In the process of investigating the land, he learned that the state ofLouisiana is actually shrinking by 50 square miles each year, due to erosioncaused by the Mississippi River. Since Fred is hoping to live in this house therest of his life, he needs to know if his land is going to be lost toerosion. After doing more research, Fred has learned that the land that isbeing 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 belowthe X axis are in the water. The semicircle has an area of 0 at the beginningof year 1. (Semicircle illustrated in the Figure.) 

Input

The first line of input will be a positive integer indicating how manydata sets will be included (N). Each of the next N lines will contain the X andY Cartesian coordinates of the land Fred is considering. These will be floatingpoint 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 shouldtake 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 from1) this property will be within the semicircle AT THE END OF YEAR Z. Z must bean integer. After the last data set, this should print out “END OF OUTPUT.”

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.

Hint

1.No property will appear exactly on the semicircle boundary: it willeither 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 theperiods at the ends of the lines. 

3.All locations are given in miles.

#include<stdio.h>

int main()

{

    int N,Z=0,n=0;       //N表示测试用例的个数,Z表示需要的年数,n表示财产为第几个

    float x,y;    //x为横坐标,y为纵坐标

    int flag=1;  //flag是一个标志,赋初值为1,测试用例结束后赋为0,结束循环

    scanf("%d",&N);      //输入N

    scanf("%f%f",&x,&y); //输入横纵坐标

    while(flag)

    {

       if(((100*Z)/3.14-(x*x+y*y))>=0)   

       {      //判断,当半圆的半径大于等于输入的点到原点的距离时,n加一个,输出Z,N减少一个

           n=n+1;

           printf("Property %d: Thisproperty will begin eroding in year %d.\n",n,Z);       //输出

           N=N-1;

           if(N==0)

           {          //判断,如果N=0,赋flag=0,跳出循环,结束

              flag=0;

              printf("END OFOUTPUT.\n");

              break;

           }

           scanf("%f%f",&x,&y);     //如果N不等于0,继续输入

       }

       else       //当半圆的半径小于输入的点到原点的距离时,Z加1,继续循环,直到找到满足条件的Z

       {

           Z=Z+1;

       }

    }

    return 0;

}

猜你喜欢

转载自blog.csdn.net/xu_benjamin/article/details/80998478