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. 数据结构系列之2-3-4树的插入、查找、删除和遍历完整版源代码实现与分析(dart语言实现)

    本文属于原创,转载请注明来源. 在上一篇博文中,详细介绍了2-3树的操作(具体地址:https://www.cnblogs.com/outerspace/p/10861488.html),那么对于更多 ...

  2. 【Linux开发】全面的framebuffer详解

    全面的framebuffer详解 一.FrameBuffer的原理 FrameBuffer 是出现在 2.2.xx 内核当中的一种驱动程序接口. Linux是工作在保护模式下,所以用户态进程是无法象D ...

  3. 【Qt开发】【Linux开发】调试记录:QFontDatabase::loadFromCache Error

    最近做嵌入式的Qt界面,在移植成功后遇到了一个问题:QFontDatabase::loadFromCache: Font path doesn't match.后面跟着便是两个路径. 解决方案就是对比 ...

  4. MySQL-快速入门(8)存储过程、存储函数

    1.存储过程 1>创建存储过程:create procedure create procedure sp_name ([in | out | inout] param_name type) [c ...

  5. JavaScript event对象clientX,offsetX,screenX异同

    event对象是JavaScript中最重要的对象之一,他代表了各种事件的状态,在各种事件的事件处理中经常用到,比如键盘活动.鼠标活动等等,其中有几个对象官方说的比较模糊,很难理解,这里有必要通俗化的 ...

  6. JS基础篇--JS获取元素的宽高以及offsetTop,offsetLeft等的属性值

    $(obj).width()与$(obj).height() $(obj).width()与$(obj).height() :jquery方式获取元素的宽高,不包括滚动条与工具条 $(obj).wid ...

  7. oracle跟SQL Server 2005 的区别

    Oracle与Sql server的区别   一直搞不明白Oracle数据库和sql server的区别,今天我特意查资料把他们的区别整理出来 Oracle数据库:Oracle Database,又名 ...

  8. catch that cow POJ 3278 搜索

    catch that cow POJ 3278 搜索 题意 原题链接 john想要抓到那只牛,John和牛的位置在数轴上表示为n和k,john有三种移动方式:1. 向前移动一个单位,2. 向后移动一个 ...

  9. [LeetCode] 135. 分发糖果

    题目链接 : https://leetcode-cn.com/problems/candy/ 题目描述: 老师想给孩子们分发糖果,有 N 个孩子站成了一条直线,老师会根据每个孩子的表现,预先给他们评分 ...

  10. python 发送kafka

    python 发送kafka大体有三种方式 1 发送并忘记(不关注是否正常到达,不对返回结果做处理) 1 import pickle 2 import time 3 from kafka import ...