Area

原创 2012年03月26日 16:35:49

点击打开链接

Jerry, a middle school student, addicts himself to mathematical research. Maybe the problems he has thought are really too easy to an expert. But as an amateur, especially as a 15-year-old boy, he had done very well. He is so rolling in thinking the mathematical problem that he is easily to try to solve every problem he met in a mathematical way. One day, he found a piece of paper on the desk. His younger sister, Mary, a four-year-old girl, had drawn some lines. But those lines formed a special kind of concave polygon by accident as Fig. 1 shows.

Fig. 1 The lines his sister had drawn
"Great!" he thought, "The polygon seems so regular. I had just learned how to calculate the area of triangle, rectangle and circle. I'm sure I can find out how to calculate the area of this figure." And so he did. First of all, he marked the vertexes in the polygon with their coordinates as Fig. 2 shows. And then he found the result--0.75 effortless.

Fig.2 The polygon with the coordinates of vertexes
Of course, he was not satisfied with the solution of such an easy problem. "Mmm, if there's a random polygon on the paper, then how can I calculate the area?" he asked himself. Till then, he hadn't found out the general rules on calculating the area of a random polygon. He clearly knew that the answer to this question is out of his competence. So he asked you, an erudite expert, to offer him help. The kind behavior would be highly appreciated by him.

Input

The input data consists of several figures. The first line of the input for each figure contains a single integer n, the number of vertexes in the figure. (0 <= n <= 1000).

In the following n lines, each contain a pair of real numbers, which describes the coordinates of the vertexes, (xi, yi). The figure in each test case starts from the first vertex to the second one, then from the second to the third, ���� and so on. At last, it closes from the nth vertex to the first one.

The input ends with an empty figure (n = 0). And this figure not be processed.

Output

As shown below, the output of each figure should contain the figure number and a colon followed by the area of the figure or the string "Impossible".

If the figure is a polygon, compute its area (accurate to two fractional digits). According to the input vertexes, if they cannot form a polygon (that is, one line intersects with another which shouldn't be adjoined with it, for example, in a figure with four lines, the first line intersects with the third one), just display "Impossible", indicating the figure can't be a polygon. If the amount of the vertexes is not enough to form a closed polygon, the output message should be "Impossible" either.

Print a blank line between each test cases.

Sample Input

5
0 0
0 1
0.5 0.5
1 1
1 0
4
0 0
0 1
1 0
1 1
0

Output for the Sample Input

Figure 1: 0.75
Figure 2: Impossible
&&&&&&&&&&&&&&&&&&&&&&&&
判断是否相交;求面积;面积公式;
#include<stdio.h>
#include<math.h>
struct point 
{
	double x,y;
}g[1008];
double MIN(double a,double b)
{
	return a>b?b:a;
}
double MAX(double a,double b)
{
	return a>b?a:b;
}
double cross_segment(point a,point b,point c)
{
	return (c.x-a.x)*(b.y-a.y)-(b.x-a.x)*(c.y-a.y);
}
int onsegment(point a,point b,point c)
{
	double d1=MIN(a.x,b.x);
	double d2=MAX(a.x,b.x);
	double d3=MIN(a.y,b.y);
	double d4=MAX(a.y,b.y);
	if(d1<=c.x&&d2>=c.x&&d3<=c.y&&d4>=c.y)
	return 1;
	return 0;
}
int segment(point a,point b,point c,point d)
{
	double d1=cross_segment(c,d,a);
	double d2=cross_segment(c,d,b);
	double d3=cross_segment(a,b,c);
	double d4=cross_segment(a,b,d);
	if(((d1>0&&d2<0)||(d1<0&&d2>0))&&((d3<0&&d4>0)||(d3>0&&d4<0)))
	return 1;
	else if(d1==0&&onsegment(c,d,a))
	return 1;
	else if(d2==0&&onsegment(c,d,b))
	return 1;
	else if(d3==0&&onsegment(a,b,c))
	return 1;
	else if(d4==0&&onsegment(a,b,d))
	return 1;
	return 0;
}
double Area(point q[],int m)
{
	int i,j,k;
	double sum1=0.0,sum2=0.0;
	for(i=0;i<m;i++)
	{
		sum1+=g[(i+1)%m].y*g[i].x;
		sum2+=g[(i+1)%m].y*g[(i+2)%m].x;
	}
	return fabs(sum2-sum1)/2.0;
}
int is_ploy(point q[],int m)
{
	int i,j,k;
	for(i=0;i<m;i++)
	{
		for(j=i+1;j<m;j++)
		{
			if(j!=i+1&&(j+1)%m!=i&&segment(g[i],g[i+1],g[j],g[j+1]))
			return 0;
		}
	}
	return 1;
}

int main()
{
	int i,j,k,m,n,ncase=1;
	while(scanf("%d",&m),m)
	{
		if(ncase!=1)
		printf("\n");
		for(i=0;i<m;i++)
		scanf("%lf%lf",&g[i].x,&g[i].y);
		if(m<=2)
		{
			printf("Figure %d: Impossible\n",ncase++);
			continue;
		}
		printf("Figure %d: ",ncase++);
		if(is_ploy(g,m))
		printf("%.2lf\n",Area(g,m));
		else
		printf("Impossible\n"); 
	}
	return 0;
}


Designing an IBM Storage Area Network

  • 2014年12月22日 10:52
  • 10.32MB
  • 下载

area 省市区数据

  • 2017年09月20日 14:27
  • 148KB
  • 下载

ASP.NET MVC - Area的路由映射(使用NampSpace)

在开始之前,首先来看2个问题。 如果有一个Area叫Database,在它的下面有一个Controller名字叫做Browse。 另外我在顶层也有一个Controller,名字也叫Browse。 ...
  • jackvs
  • jackvs
  • 2012年07月27日 13:09
  • 11812

WebAPI支持Area示例程序

  • 2017年01月17日 16:28
  • 24.12MB
  • 下载

MVC 如何设定默认默认路由为指定的Area下的某个action

MVC中,一般的情况下,使用IDE工具帮我们生成的代码,在路由注册的时候: public static void RegisterRoutes(RouteCollection routes) ...

Area Based ADP

  • 2013年12月17日 18:44
  • 678KB
  • 下载

Asp.net MVC area文件夹下设置默认显示页面

在使用area 的时候,设置默认的显示页面,经常会碰到如下异常:“/”应用程序中的服务器错误。未找到视图“Index”或其母版视图,或没有视图引擎支持搜索的位置。搜索了以下位置: ~/Views/...
  • kai161
  • kai161
  • 2014年02月14日 09:25
  • 5960

vmvware 7.0 支持WIN7 Area效果1

  • 2010年08月17日 23:53
  • 12MB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Area
举报原因:
原因补充:

(最多只允许输入30个字)