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. 第四周课程总结&第二次实验报告

    实验二 Java简单类与对象 实验目的 掌握类的定义,熟悉属性.构造函数.方法的作用,掌握用类作为类型声明变量和方法返回值: 理解类和对象的区别,掌握构造函数的使用,熟悉通过对象名引用实例的方法和属性 ...

  2. 剑指Offer编程题(Java实现)——删除链表中重复的结点

    题目描述 在一个排序的链表中,存在重复的结点,请删除该链表中重复的结点,重复的结点不保留,返回链表头指针. 例如,链表1->2->3->3->4->4->5 处理后 ...

  3. ubutu16.04编译安装apache

    // 安装编译器 sudo apt-get install build-essential // 下载所需依赖及apache2源码包 wget --no-check-certificate https ...

  4. 消息中间件 JMS入门

    1. JMS入门 1.1消息中间件 什么是消息中间件 消息中间件利用高效可靠的消息传递机制进行平台无关的数据交流,并基于数据通信来进行分布式系统的集成.通过提供消息传递和消息排队模型,它可以在分布式环 ...

  5. mac键盘在ubuntu下开启fn功能按键

    转载:http://wiki.ubuntu.org.cn/UbuntuHelp:AppleKeyboard Change Function Key behavior This section of t ...

  6. CodeForces - 714E + POJ - 3666 (dp严格单调递增与非严格单调递增)

    左偏树 炒鸡棒的论文<左偏树的特点及其应用> 虽然题目要求比论文多了一个条件,但是……只需要求非递减就可以AC……数据好弱…… 虽然还没想明白为什么,但是应该觉得应该是这样——求非递减用大 ...

  7. ECMAScript 6 学习笔记(一)

    ECMAScript 6简介 ECMAScript 6.0(以下简称ES6)是JavaScript语言的下一代标准,已经在2015年6月正式发布了.它的目标,是使得JavaScript语言可以用来编写 ...

  8. 安装RF

    pip install robotframework wxPython pip install robotframework-ride pip install --pre --upgrade robo ...

  9. linux NFS 自动挂载

    NFS 自动挂载的两种方法 第一种: 需要注意的事项 开机挂载的命令不能写入到/etc/fstab 中,由于 NFS 依赖于网络,而/etc/fstab 的引用是在计算机 网络尚未启动的时候就开始引导 ...

  10. WithEvents的一些用法

    WithEvents的一些用法说明:1.WithEvents是指定一个或多个已声明成员变量引用可引发事件的类的实例.2.当某个变量是使用 WithEvents 定义时,可以用声明方式指定某个方法使用 ...