Problem Description
Josh Lyman is a gifted painter. One of his great works is a glass painting. He creates some well-designed lines on one side of a thick and polygonal glass, and renders it by some special dyes. The most fantastic thing is that it can generate different meaningful paintings by rotating the glass. This method of design is called “Rotational Painting (RP)” which is created by Josh himself.

You are a fan of Josh and you bought this glass at the astronomical sum of money. Since the glass is thick enough to put erectly on the table, you want to know in total how many ways you can put it so that you can enjoy as many as possible different paintings hiding on the glass. We assume that material of the glass is uniformly distributed. If you can put it erectly and stably in any ways on the table, you can enjoy it.

More specifically, if the polygonal glass is like the polygon in Figure 1, you have just two ways to put it on the table, since all the other ways are not stable. However, the glass like the polygon in Figure 2 has three ways to be appreciated. 

Pay attention to the cases in Figure 3. We consider that those glasses are not stable.

 
Input
The input file contains several test cases. The first line of the file contains an integer T representing the number of test cases. 
For each test case, the first line is an integer n representing the number of lines of the polygon. (3<=n<=50000). Then n lines follow. The ith line contains two real number xi and yi representing a point of the polygon. (xi, yi) to (xi+1, yi+1) represents a edge of the polygon (1<=i<n), and (xn,yn) to (x1, y1) also represents a edge of the polygon. The input data insures that the polygon is not self-crossed.
 
Output
For each test case, output a single integer number in a line representing the number of ways to put the polygonal glass stably on the table.
 
题目大意:给一个简单多边形,问有多少种方法可以把这个多边形竖直稳定地放在一个平面上,如图所示。
思路:物理学告诉我们,要解决这个问题,首先要求出这个多边形质心,然后枚举每一种放法,看质心到地板的垂线是否在底边之间。
令G(i) = cross(p[i], p[i+1]), 质心为t,多边形的点集为p,cross为叉积。
那么t.x = sum(cross(p[i], p[i+1]) / 2 * (p[i].x + p[i + 1].x) / 3) / sum(cross(p[i], p[i+1]) / 2)
t.y = sum(cross(p[i], p[i+1]) / 2 * (p[i].y + p[i + 1].y) / 3) / sum(cross(p[i], p[i+1]) / 2)
这里不证明。
然后在不考虑稳定的情况下,多边形的放法显然取决于这个多边形的凸包的边数。
枚举凸包的每一条边,判断质心到地板的垂线的垂足是否在凸包的那条边之中。
若质心为O,底边的两点分别为A、B,那么垂足在AB上当且仅当∠OAB和∠OBA都为锐角。
那么向量AO和向量AB的点积为正数,那么∠OAB为锐角,∠OBA同理。
此题解决。
 
代码(281MS):
 #include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
typedef long long LL; const int MAXN = ;
const double EPS = 1e-; inline int sgn(double x) {
return (x > EPS) - (x < -EPS);
} struct Point {
double x, y;
Point(double x = , double y = ): x(x), y(y) {}
void read() {
scanf("%lf%lf", &x, &y);
}
Point operator + (const Point &rhs) const {
return Point(x + rhs.x, y + rhs.y);
}
Point operator - (const Point &rhs) const {
return Point(x - rhs.x, y - rhs.y);
}
double operator * (const Point &rhs) const {
return x * rhs.x + y * rhs.y;
}
Point operator / (const double &rhs) const {
return Point(x / rhs, y / rhs);
}
bool operator < (const Point &rhs) const {
if(y != rhs.y) return y < rhs.y;
return x < rhs.x;
}
};
typedef Point Vector; double cross(const Point &a, const Point &b) {
return a.x * b.y - a.y * b.x;
} double cross(const Point &sp, const Point &op, const Point &ep) {
return cross(sp - op, ep - op);
} void Graham_scan(Point *p, int n, int *stk, int &top) {
sort(p, p + n);
top = ;
stk[] = ; stk[] = ;
for(int i = ; i < n; ++i) {
while(top && cross(p[stk[top - ]], p[stk[top]], p[i]) <= ) --top;
stk[++top] = i;
}
int len = top;
stk[++top] = n - ;
for(int i = n - ; i >= ; --i) {
while(top != len && cross(p[stk[top - ]], p[stk[top]], p[i]) <= ) --top;
stk[++top] = i;
}
} Point barycenter(Point *p, int n) {
double area = ;
Point res;
for(int i = ; i < n; ++i) {
double t = cross(p[i], p[i + ]) / ;
res.x += t * (p[i].x + p[i + ].x) / ;
res.y += t * (p[i].y + p[i + ].y) / ;
area += t;
}
return res / area;
} Point p[MAXN];
int stk[MAXN], top;
int n, T; int main() {
scanf("%d", &T);
while(T--) {
scanf("%d", &n);
for(int i = ; i < n; ++i) p[i].read();
p[n] = p[];
Point O = barycenter(p, n);
Graham_scan(p, n, stk, top); int ans = ;
for(int i = ; i < top; ++i) {
Point &A = p[stk[i]], &B = p[stk[i + ]];
ans += (sgn((O - A) * (B - A)) > && sgn((O - B) * (A - B)) > );
}
printf("%d\n", ans);
}
}

HDU 3685 Rotational Painting(多边形质心+凸包)(2010 Asia Hangzhou Regional Contest)的更多相关文章

  1. HDU 3686 Traffic Real Time Query System(双连通分量缩点+LCA)(2010 Asia Hangzhou Regional Contest)

    Problem Description City C is really a nightmare of all drivers for its traffic jams. To solve the t ...

  2. HDU 3689 Infinite monkey theorem(DP+trie+自动机)(2010 Asia Hangzhou Regional Contest)

    Description Could you imaging a monkey writing computer programs? Surely monkeys are smart among ani ...

  3. HDU 3695 / POJ 3987 Computer Virus on Planet Pandora(AC自动机)(2010 Asia Fuzhou Regional Contest)

    Description Aliens on planet Pandora also write computer programs like us. Their programs only consi ...

  4. HDU 3721 Building Roads (2010 Asia Tianjin Regional Contest) - from lanshui_Yang

    感慨一下,区域赛的题目果然很费脑啊!!不过确实是一道不可多得的好题目!! 题目大意:给你一棵有n个节点的树,让你移动树中一条边的位置,即将这条边连接到任意两个顶点(边的大小不变),要求使得到的新树的直 ...

  5. HDU 3726 Graph and Queries(平衡二叉树)(2010 Asia Tianjin Regional Contest)

    Description You are given an undirected graph with N vertexes and M edges. Every vertex in this grap ...

  6. HDU 3698 Let the light guide us(DP+线段树)(2010 Asia Fuzhou Regional Contest)

    Description Plain of despair was once an ancient battlefield where those brave spirits had rested in ...

  7. HDU 3697 Selecting courses(贪心+暴力)(2010 Asia Fuzhou Regional Contest)

    Description     A new Semester is coming and students are troubling for selecting courses. Students ...

  8. HDU 3699 A hard Aoshu Problem(暴力枚举)(2010 Asia Fuzhou Regional Contest)

    Description Math Olympiad is called “Aoshu” in China. Aoshu is very popular in elementary schools. N ...

  9. HDU 3696 Farm Game(拓扑+DP)(2010 Asia Fuzhou Regional Contest)

    Description “Farm Game” is one of the most popular games in online community. In the community each ...

随机推荐

  1. 将所有程序设置XML集中到一个单独XML配置文件的方法:使用appSettings元素的configSource元素

    在.NET程序中,程序的配置文件默认都会放在程序根目录下的web.config(网站程序)或App.config(控制台等程序),在该配置文件中可以定义若干程序配置信息. 在此以网站程序为例,首先将下 ...

  2. QProgressBar的使用例子

    今天下午动手实践了一下QProgressBar,遇到的问题比较多,浪费了不少时间,但收获同样颇多... 程序界面如下:  1 // progressbar.h  2   3 #ifndef PROGR ...

  3. Shell 字符串常见操作

    参考文章:http://blog.csdn.net/chen_jp/article/details/8922582 一 字符替换 origin=原字符串  str=替换后的字符串 替换命令: str= ...

  4. BAT(批处理)获得参数

    原文转自:http://blog.csdn.net/luhouxiang/article/details/31733049 获取参数有2种, 一种为从命令行输入参数,使用两个%中间包含数字表示,数字从 ...

  5. Java实验三报告

    一.  实验内容 (一)敏捷开发与XP 摘要:一项实践在XP环境中成功使用的依据通过XP的法则呈现,包括:快速反馈.假设简单性.递增更改.提倡更改.优质工作.XP软件开发的基石是XP的活动,包括:编码 ...

  6. SQLSERVER 16进制与10进制转换

    最近工控项目中遇到的16进制与10进制转换,在.NET中比较容易实现,在SQLSERVER中发现没有直接的转换,尤其是出现超出范围的long负数,即无符号64位整数在sqlserver中的存储.网上找 ...

  7. 错误提示: An App ID with identifier "*****" is not avaliable. Please enter a different string.

    百度了很多,但大多的解决办法就是 更改BundleID,的确管用,,但是有的情况下,你需要跟同事合作,公用同一个BundleID, 我是这样处理的:工具栏中打开Window—project删除所有工程 ...

  8. HTML5样式和列表、CSS链接的四种状态

    一.HTML5样式 1.标签: <style>:样式定义: <link>:资源引用: 2.属性: type="text/css":引入文档类型: rel=& ...

  9. Selenium2学习-006-WebUI自动化实战实例-004-解决 Chrome 浏览器证书提示:--ignore-certificate-errors

    此文主要讲述 Java 运行 Selenium 脚本时,如何消除 Chrome 浏览器启动后显示的证书错误报警提示,附带 Chrome 参数使浏览器最大化的参数. 希望能对初学 Selenium2 W ...

  10. MVC中@Html.DisPlayFor(model=>model.newsName)和 @Model.newsName的区别

    MVC中,在Controllers查询到数据,返回一个实体给View并显示,可以用@Html.DisPlayFor(model=>model.newsName)和 @Model.newsName ...