ZOJ 1010 Area

ZOJ Problem Set - 1010
Area

Time Limit: 2 Seconds         Memory Limit: 65536 KB         Special Judge

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 <wbr>1010 <wbr>Area
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 <wbr>1010 <wbr>Area
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


Source: Asia 2001, Shanghai (Mainland China)
源码:

ZOJ <wbr>1010 <wbr>Area
ZOJ <wbr>1010 <wbr>Area
ZOJ <wbr>1010 <wbr>Area

解题报告:
    题目大意:对于任意给出的点,计算出他们的所围成的多边形面积,同时也要判断该多边形是否满足
    条件。
    算法思想:本题是数学题,较为复杂,单独的计算多边形的面积比较简单,对于三角形的面积
    计算,已知三点a,b,c,ab叉乘ac的绝对值即为面积的一半,可以推导出多边形的面积公式。
    多边形的顶点p0,p1,p2,p3,p4....,S=0.5*(p0*p1+p1*p2+p3*p4....+pn*p0).
    其次,还要判断该多边形是否满足,判断是否任意两边会相交,任意两边的顶点会重合这些都不满足要求
    由题意,该多边形的构造是在给出的点的顺序连线而成。所以任意两边我们可以直接用下标来表示:s,t,表示的是边(s,s+1)和边(t,t+1)
    判断(s,s+1)和(t,t+1)是否相交,判断t点和t+1点是否在边(s,s+1)两侧,可以用叉乘判断,X叉乘Y和Y叉乘X符号相反
    可以利用这个性质判断,只要看sXt sX(t+1) 符号是否相反。
    判断(s,s+1)和(t,t+1)是否有重点时,有两个标准可以判断,对于s,t,t+1(1)如果按上述计算的叉乘=0,说明三点在一条线上,(2)如果他们的点乘=0,说明垂直,如果同时满足以上条件即可说明有重点。
    以上的判断,都要做4次,分别以s,s+1,t,t+1,做参考。
    上面的工作做完后,就要对该多边形的所有两两不同的边进行判断,需要注意的是,x[0],y[0]存放了点n的坐标,所以最后一步不用判断。即边(0,1)和边(n-1,n)肯定相交。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值