poj 1005 I Think I Need a Houseboat

简介:

有一个水题,题目读懂就可以了,千万注意是“半圆”!!!


题目大意:已知一个圆心为(0,0),半径随时间增长的位于X轴上方的半圆,初始面积为0,每年的面积增加50,给出一个坐标,求该坐标在第几年被该半圆覆盖。

代码:


#include <stdio.h>

int main()
{
	int n;
	scanf("%d",&n);

	int i;
	double x,y;
	int year;
	for(i=1;i<=n;i++)
	{
		scanf("%lf%lf",&x,&y);
			
		//如果以(x,y)为半径的圆面积小于水域面积,就被淹没了,这样就不用求水域半径了
		year=(int)((x*x+y*y)*3.1415926/100+1);	//根据坐标计算年份
		
		printf("Property %d: This property will begin eroding in year %d.\n",i,year);
	}
	printf("END OF OUTPUT.\n");

	return 0;
}


这段代码写的繁琐点,不过思路更清晰


#include <stdio.h>

int main()
{
	int n;
	scanf("%d",&n);

	int i;
	double x,y;
	int year;
	int area;
	double s;
	for(i=1;i<=n;i++)
	{
		scanf("%lf%lf",&x,&y);
			
		//如果以(x,y)为半径的圆面积小于水域面积,就被淹没了,这样就不用求水域半径了
		s=3.1415926*(x*x+y*y)/2;
		area=0;
		for(year=1; ;year++)
		{
			area+=50;
			if(s<area)
				break;
		}
		
		printf("Property %d: This property will begin eroding in year %d.\n",i,year);
	}
	printf("END OF OUTPUT.\n");

	return 0;
}


目录
打赏
0
0
0
0
17
分享
相关文章
POJ 1659
点击打开链接 Havel-hakimi  定理    判断可图性  简单的说,判断序列 7,7,4,3,3,3,2,1  是否可图,删除首项,其后的首项个数项每项-1后排序,由于图中不可能出现负度数的点,一旦发现负数,即不可图。7,7,4,3,3,3,2,1--&gt; 6,3,2,2,2,1,0 --&gt; 2,1,1,1,0,-1.(over)。 再举一个例子,判断序列:5,4
1112 0
poj-2551-ones
Description Given any integer 0
797 0
POJ 1012 Joseph
Joseph Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 53862   Accepted: 20551 Description The Joseph's problem is notoriously known.
859 0
POJ 1011
http://www.cnblogs.com/linpeidong2009/archive/2012/04/23/2467048.html http://blog.163.com/xdu_cfcry/blog/static/1694623032010718274132/
649 0
POJ 2244
/* 大致题意:n个城市,先把1号断电,继而每隔m断电使标号为2的最后被限电; 转化为(n-1)个城市,最后断电的为标号为1的城市,求最小的m */ #include bool is_joseph(int m,int n) { int i,j; int s=0;...
637 0
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等