[ZJU 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.
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
Source: Asia 2001, Shanghai (Mainland China)
#include<bits/stdc++.h>
using namespace std;
typedef struct point
{
double x;
double y;
}Point;
bool lineIntersectSide(Point A, Point B, Point C, Point D)
{
double fC = (C.y - A.y) * (A.x - B.x) - (C.x - A.x) * (A.y - B.y);
double fD = (D.y - A.y) * (A.x - B.x) - (D.x - A.x) * (A.y - B.y); if(fC * fD > )
return false; return true;
}
bool sideIntersectSide(Point A, Point B, Point C, Point D)
{
if(!lineIntersectSide(A, B, C, D))
return false;
if(!lineIntersectSide(C, D, A, B))
return false;
return true;
}
Point a[];
int n;
int ID;
double CALC(Point a,Point b)
{
return (a.x + b.x) * (b.y - a.y) / ;
}
void solve()
{
cout << "Figure " << ID << ": ";
for (int i=;i<=n;i++)
cin >> a[i].x >> a[i].y;
if (n <= )
{
cout << "Impossible\n\n";
return;
}
for (int i=;i<=n;i++)
for (int j=;j<=n;j++)
{
if (i == j || i%n+ == j || i == j%n+ || i%n+ == j%n+) continue;
if (sideIntersectSide(a[i],a[i%n+],a[j],a[j%n+]))
{
cout << "Impossible\n\n";
return;
}
}
double ANS=;
for (int i=;i<=n;i++)
ANS += CALC(a[i],a[i%n+]);
printf("%.2f\n\n",abs(ANS));
}
int main()
{
while (cin >> n,n)
ID++,solve();
}
[ZJU 1010] Area的更多相关文章
- [ZOJ 1010] Area (计算几何)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1010 题目大意:给你n个点,问你顺次连线能否连成多边形?如果能, ...
- zoj 1010 Area【线段相交问题】
链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1010 http://acm.hust.edu.cn/vjudge/ ...
- 1010 Area
题目要求面积和判断非相邻边不相交.和数学和几何有关系. #include <stdio.h> #include <math.h> #define MISS 0.0000001 ...
- POJ题目细究
acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP: 1011 NTA 简单题 1013 Great Equipment 简单题 102 ...
- 【转】POJ百道水题列表
以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...
- ACM 计算几何向量
向量 简介注意事项基本计算 加减法 ~ 示例代码 长度 ~ 示例代码 数乘 ~ 示例代码 点积 应用 ~ 示例代码 叉积 ~ 示例代码 性质与应用 经典题目 向量旋转 操作目的 模板代码 简介 向量, ...
- zoj 1010 (线段相交判断+多边形求面积)
链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=10 Area Time Limit: 2 Seconds Mem ...
- 浙江大学PAT考试1009~1012(1010上帝是冠军。。)
哎,pat1010即使java书面,只有java书面,还增加了两个点,,.啊,智商捉佳,主要pat有些不给明确的范围.造成遐想空间.. 还是按顺序介绍.. 题目地址:http://pat.zju.ed ...
- POJ 2546 & ZOJ 1597 Circular Area(求两圆相交的面积 模板)
题目链接: POJ:http://poj.org/problem? id=2546 ZOJ:problemId=597" target="_blank">http: ...
随机推荐
- python每日一练:0012题
第 0012 题: 敏感词文本文件 filtered_words.txt,里面的内容 和 0011题一样,当用户输入敏感词语,则用 星号 * 替换,例如当用户输入「北京是个好城市」,则变成「**是个好 ...
- java 内部编译异常的处理方法
1.可能存在的问题. 在cmd 输入 java -version 和javac -version 检验java的环境是否正常,不正常就卸载重装. 搞定!
- 解决MySql忘记密码
描述:忘记了mysql的登录密码,无法登录的情况下该怎么办? 环境:CentOS 7,数据库:mysql 5.7 1.停止数据库(先查看mysql服务是否运行) # ps -ef | -i grep ...
- 打印页面内容,<input>不好使,用<textarea> 代替
<textarea class="sld-textarea" onchange="changeTextareaValue(this)">123< ...
- [2019多校联考(Round 6 T3)]脱单计划 (费用流)
[2019多校联考(Round 6 T3)]脱单计划 (费用流) 题面 你是一家相亲机构的策划总监,在一次相亲活动中,有 n 个小区的若干男士和 n个小区的若干女士报名了这次活动,你需要将这些参与者两 ...
- nginx下载安装和虚拟机的配置
一. Nginx下载安装 1.Nginx下载:nginx-1.13.0.tar.gz,下载到:/usr/local/software/ wget http://nginx.org/download/n ...
- CSUST 8.5 早训
## Problem A A - Meeting of Old Friends CodeForces - 714A 题意: 解题说明:此题其实是求两段区间的交集,注意要去除掉交集中的某个点. 题解: ...
- IDEA 增加对JPA的支持 执行JPQL语句
IDEA 可以在控制台console中执行JPQL语句: 1. 在已存在的项目中选择项目结构: 2. 选择模块-指定实体所在的模块-选择上面的号 2. 选择要添加的模块:我们使用的是JPA,也可能有的 ...
- elementUI 等 UI框架中,@change方法传递参数
有些业务中,在使用 @change 回调的时候需要动态获取当前循环下的特定值,但是@change方法一旦传递参数就会覆盖原本的数据,对此,有两种方法解决: // 这种方法据说会改变 this 指向 ...
- 前端开发HTML&css入门——一些其他常用的文本标签
em标签和strong标签 i标签和b标签 small标签 cite标签 q标签和blockquote标签 em主要表示语气上的强调,em在浏览器中默认使用斜体显示strong表示强调的内容,比em更 ...