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.


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)


solution:
  每次读入后暴力判断两线是否相交。后用微积分思想解决。
  注意在n<3时输出Impossible。
#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的更多相关文章

  1. [ZOJ 1010] Area (计算几何)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1010 题目大意:给你n个点,问你顺次连线能否连成多边形?如果能, ...

  2. zoj 1010 Area【线段相交问题】

    链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1010 http://acm.hust.edu.cn/vjudge/ ...

  3. 1010 Area

    题目要求面积和判断非相邻边不相交.和数学和几何有关系. #include <stdio.h> #include <math.h> #define MISS 0.0000001 ...

  4. POJ题目细究

    acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP:  1011   NTA                 简单题  1013   Great Equipment     简单题  102 ...

  5. 【转】POJ百道水题列表

    以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...

  6. ACM 计算几何向量

    向量 简介注意事项基本计算 加减法 ~ 示例代码 长度 ~ 示例代码 数乘 ~ 示例代码 点积 应用 ~ 示例代码 叉积 ~ 示例代码 性质与应用 经典题目 向量旋转 操作目的 模板代码 简介 向量, ...

  7. zoj 1010 (线段相交判断+多边形求面积)

    链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=10 Area Time Limit: 2 Seconds      Mem ...

  8. 浙江大学PAT考试1009~1012(1010上帝是冠军。。)

    哎,pat1010即使java书面,只有java书面,还增加了两个点,,.啊,智商捉佳,主要pat有些不给明确的范围.造成遐想空间.. 还是按顺序介绍.. 题目地址:http://pat.zju.ed ...

  9. POJ 2546 &amp; ZOJ 1597 Circular Area(求两圆相交的面积 模板)

    题目链接: POJ:http://poj.org/problem? id=2546 ZOJ:problemId=597" target="_blank">http: ...

随机推荐

  1. 【ABAP系列】SAP 系统的消息类型分析 MESSAGE TYPE

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP 系统的消息类型分析 ME ...

  2. centos7 VM虚拟机在主机关机重启后,无法ping通

    解决办法 1.虚拟机的某些网络相关的服务没有启动,打开电脑的服务启动相关服务 2.打开虚拟机的虚拟网络设置,恢复默认设置即可 3.判定虚拟网卡的网关和centos的网关是否一致,如果不一致,改成一致, ...

  3. django groupby 用法

  4. [Git] 022 没有人是一座孤岛

    0.回顾 [Git] 015 远程仓库篇 第二话 关联与推送 的 "2" 中介绍过 git remote git remote -v 与 "status" 不同 ...

  5. Larkin’s NOI

    Larkin’s NOI Problem Description Larkin has been to Yantai to take part in NOI 2010!众所周知(do you know ...

  6. int快读

    昨天偶然间看到CJ_tony的快读,所以便决定学习一下. 这个快读的原理就是:读入单个字符要比读入读入数字快,先读入字符,然后再转化成数字.(原理的话大学再研究) 代码: #include<io ...

  7. React事件绑定的几种方式对比

    React事件绑定 由于类的方法默认不会绑定this,因此在调用的时候如果忘记绑定,this的值将会是undefined.通常如果不是直接调用,应该为方法绑定this.绑定方式有以下几种: 1. 在构 ...

  8. 工作日记之查看Linux系统里面的启动频率2017_02_07

    链接:http://www.jb51.net/LINUXjishu/19905.html 查看Linux里面的batch: cat /etc/crontab (1)0 19 * * 6 root /d ...

  9. 区块链开源实现hyperledger fabric架构详解

    hyperledger fabric是区块链中联盟链的优秀实现,主要代码由IBM.Intel.各大银行等贡献,目前v1.1版的kafka共识方式可达到1000/s次的吞吐量.本文中我们依次讨论:区块链 ...

  10. Linux基础命令四

    iptables iptables -F:关闭防火墙 crontab -l查看定时任务 crontab -e :编辑定时任务 log日志相关: ls  /var/log:查看日志 du -sh  /v ...