Area

 

Time Limit: 2000 msMemory Limit: 65536 KB

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.

ZOJ 1010 Area_C语言
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.

ZOJ 1010 Area_C语言_02
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

 

 

区域

 

杰瑞是一名中学生,沉迷于数学研究。也许他想的问题对专家来说真的太容易了。但作为一个业余爱好者,尤其是作为一个15岁的男孩,他做得很好。他在思考这道数学问题时是如此地动脑筋,以至于他很容易地试图用数学方法解决他遇到的每一个问题。有一天,他在桌子上发现了一张纸。他的妹妹,玛丽,一个四岁的女孩,画了一些线。但这些线条偶然形成了一种特殊的凹多边形,如图1所示。

ZOJ 1010 Area_C语言

图1他姐姐画的线

 

“太棒了!”他想,“这个多边形看起来很有规律。我刚刚学会了如何计算三角形、矩形和圆的面积。我相信我能找到计算这个数字面积的方法。”于是他就这么做了。首先,他在多边形中用坐标标记顶点,如图2所示。然后他发现结果是,0。75。

ZOJ 1010 Area_C语言_02

图2顶点坐标的多边形

 

当然,他对这么简单的问题的解决并不满意。“嗯,如果纸上有一个随机的多边形,那我怎么计算面积呢?”他问自己。直到那时,他还没有发现计算任意多边形面积的一般规则。他清楚地知道这个问题的答案超出了他的能力范围。所以他请求你,一位博学的专家,来帮助他。这种善良的行为将会得到他的高度赞赏。

 

输入

输入数据由几个图形组成。每个图的输入的第一行包含单个整数n,即图中的顶点数。(0 <= n <= 1000)。

 

在接下来的n行中,每一行都包含一对实数,它们描述了顶点的坐标(xi, yi)。每个测试用例中的图形从第一个顶点开始到第二个顶点,然后从第二个顶点开始到第三个顶点,以此类推。最后,它从第n个顶点到第一个顶点闭合。

 

输入以一个空的数字结束(n = 0),这个数字不被处理。

 

输出

如下所示,每个图的输出应该包含图号和冒号,冒号后面是图的区域或字符串“Impossible”。

 

如果图形是一个多边形,计算它的面积(精确到两个小数)。根据输入的顶点,如果不能形成一个多边形(即一条线与另一条线不能相交,如有四条线的图形,第一条线与第三条线相交),只显示“不可能”,表示该图形不可能是多边形。如果顶点的数量不足以形成一个封闭的多边形,那么输出消息也应该是“不可能的”。

 

在每个测试用例之间打印一个空白行。

 

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

 

ZOJ 1010 Area_C语言_05

 

代码:

#include <stdio.h>
double det(double x1,double y1,double x2,double y2,double x3,double y3)
{
return x1*y2+x2*y3+x3*y1-x2*y1-x3*y2-x1*y3;
}
int main()
{
int n,i,j,count=0,temp;
double x[1000],y[1000],area;
while(1)
{
scanf("%d",&n);
if (n==0)
return 0;
count++;
if (count>1)
printf("\n");
printf("Figure %d: ",count);
for(i=0;i<n;i++)
scanf("%lf%lf",&x[i],&y[i]);
if(n<3)
{
printf("Impossible\n");
continue;
}
for(i=0;i<n;i++)
for(j=(i+1)/n;j<i-1;j++)
{
temp=(i+1)%n;
if(det(x[j],y[j],x[i],y[i],x[j+1],y[j+1])*det(x[j],y[j],x[temp],y[temp],x[j+1],y[j+1])<=0&&
det(x[i],y[i],x[j],y[j],x[temp],y[temp])*det(x[i],y[i],x[j+1],y[j+1],x[temp],y[temp])<=0)
{
printf("Impossible\n");
goto quit;
}
}
area=0;
for(i=0;i<n;i++)
{
area+=x[i]*y[(i+1)%n];
area-=y[i]*x[(i+1)%n];
}
if(area<0)
area*=-1;
printf("%.2lf\n",area/2);
quit:;
}
}