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. jmap -heap命令用法

    用jmap -heap命令可以查看linux堆内存分布 具体用法 1:先查出tomcat的进程号 例如: 然后执行 jmap -heap 7095 可以打印出整体的堆信息   可以看到经过分配的存活区 ...

  2. 【FICO系列】SAP ABAP&FI FI/CO接口:待更新的不一致的FI/CO凭证标题数据

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[FICO系列]SAP ABAP&FI ...

  3. cocos2dx基础篇(16) 基本绘图DrawPrimitives

    [3.x] (1)去掉前缀 "cc" (2)将 ccDraw***() 封装到了 DrawPrimitives 命名空间中. (3)重写绘图函数:         draw(Ren ...

  4. 链路聚合teaming(网卡绑定技术)2

    一.sentos7网卡绑定技术之teaming 这里介绍两种最常见的双网卡绑定模式: (1) roundrobin - 轮询模式 所有链路处于负载均衡状态,这种模式的特点增加了带宽,同时支持容错能力. ...

  5. 解读Nodejs多核处理模块cluste

    http://blog.fens.me/nodejs-core-cluster/ Node.js开发框架Express4.x   http://blog.fens.me/nodejs-express4 ...

  6. 1~n的全排列--阅文集团2018校招笔试题

    题目大意:给定整数n,求出1~n的全排列 示例 输入:n=3 输出:[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1] import java.util.S ...

  7. pg_receivewal实践

    测试从pg_receivewal的日志中恢复从库为主库: 主从配置async模式,配置pg_receivewal接收日志pg_receivewal -D /dbaas/pg/data/pg_recei ...

  8. uva-796.critical links(连通图的桥)

    本题大意:求出一个无向图的桥的个数并且按照顺序输出所有桥. 本题思路:注意判重就行了,就是一个桥的裸题. 判重思路目前知道的有两种,第一种是哈希判重,第二种和邻接矩阵的优化一样,就是只存图的上半角或者 ...

  9. php读取excel文件并导入数据库(表头任意设定)

    最近收到一个很奇葩的需求,要求上传excel员工工资表,表格表头不固定,导入后字段名为表头的拼音,每月导入一次,当月重复导入则覆盖现有的当月表头,并且可以按照在界面上按照月份筛选显示,我写的代码主要包 ...

  10. Python 多列数据存储

    zip()函数 zip函数可以把多个列表相加成一个tuple(元组) a = [1,2,3,4] b = [11,22,33,44] c = [111,222,333,444] A = list(zi ...