Rotational Painting

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2498    Accepted Submission(s): 702

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.
 
Sample Input
2
4
0 0
100 0
99 1
1 1
6
0 0
0 10
1 10
1 1
10 1
10 0
 
Sample Output
2
3

Hint

The sample test cases can be demonstrated by Figure 1 and Figure 2 in Description part.

题目大意:给一个多边形,问把它放到平面上是稳定状态的(重心在支撑点以内,在支撑点是不稳定的)种数。
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std; const double eps=1e-;
const double Pi=acos(-1.0);
struct Point
{
double x,y;
Point(double x=,double y=):x(x),y(y) {}
};
typedef Point Vector;
Vector operator +(Vector A,Vector B){return Vector(A.x+B.x,A.y+B.y);}
Vector operator -(Vector A,Vector B){return Vector(A.x-B.x,A.y-B.y);}
Vector operator *(Vector A,double p){return Vector(A.x*p,A.y*p);}
Vector operator /(Vector A,double p){return Vector(A.x/p,A.y/p);}
bool operator < (const Point &a,const Point &b)
{
return a.x<b.x||(a.x==b.x&&a.y<b.y);
}
int dcmp(double x)
{
if(fabs(x)<eps) return ;
else return x<?-:;
}
bool operator == (const Point &a,const Point &b){
return (dcmp(a.x-b.x)== && dcmp(a.y-b.y)==);
}
double Dot(Vector A,Vector B){return A.x*B.x+A.y*B.y;}//点积
double Cross(Vector A,Vector B){ return A.x*B.y-A.y*B.x;}//叉积
Point GetLineProjection(Point P,Point A,Point B)//P在直线AB上的投影点
{
Vector v=B-A;
return A+v*(Dot(v,P-A)/Dot(v,v));
}
bool OnSegment(Point p,Point a1,Point a2)//点是否在直线上(不包括端点)
{
return dcmp(Cross(a1-p,a2-p))== && dcmp(Dot(a1-p,a2-p))<;
}
Point getcenter(vector<Point> p)//多边形的重心
{
double area=;
Point c=Point(,);
int i,n=p.size();
for(i=;i<n-;i++)
{
double temp=Cross(p[i]-p[],p[i+]-p[]);
c.x+=temp*(p[i].x+p[i+].x+p[].x)/3.0;
c.y+=temp*(p[i].y+p[i+].y+p[].y)/3.0;
area+=temp;
}
c.x/=area;c.y/=area;
return c;
}
vector<Point> ConvexHull(vector<Point>& p)//求凸包
{
sort(p.begin(), p.end());
p.erase(unique(p.begin(), p.end()), p.end());
int i,n = p.size();
int m = ;
vector<Point> ch(n+);
for(i = ; i < n; i++) {
while(m > && Cross(ch[m-]-ch[m-], p[i]-ch[m-]) <= ) m--;
ch[m++] = p[i];
}
int k = m;
for(i = n-; i >= ; i--) {
while(m > k && Cross(ch[m-]-ch[m-], p[i]-ch[m-]) <= ) m--;
ch[m++] = p[i];
}
if(n > ) m--;
ch.resize(m);
return ch;
} void solve(vector<Point> p,Point center)
{
int ans=,n=p.size();
for(int i=;i<n;i++)
{
Point t=GetLineProjection(center,p[i],p[(i+)%n]);
if(OnSegment(t,p[i],p[(i+)%n])) ans++;
}
printf("%d\n",ans);
} int main()
{
int i,t,n;
double x,y;
vector<Point> p;
scanf("%d",&t);
while(t--)
{
p.clear();
scanf("%d",&n);
for(i=;i<n;i++)
{
scanf("%lf%lf",&x,&y);p.push_back(Point(x,y));
}
Point center=getcenter(p);
p=ConvexHull(p);
solve(p,center);
}
return ;
}

hdu 3685 多边形重心+凸包的更多相关文章

  1. hdu 1115(多边形重心问题)

    Lifting the Stone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  2. HDU 3685 Rotational Painting(多边形质心+凸包)(2010 Asia Hangzhou Regional Contest)

    Problem Description Josh Lyman is a gifted painter. One of his great works is a glass painting. He c ...

  3. hdu 3685 10 杭州 现场 F - Rotational Painting 重心 计算几何 难度:1

    F - Rotational Painting Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & % ...

  4. hdu 1115:Lifting the Stone(计算几何,求多边形重心。 过年好!)

    Lifting the Stone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  5. hdu 1115(计算多边形重心)

    题意:已知一多边形没有边相交,质量分布均匀.顺序给出多边形的顶点坐标,求其重心. 分析: 求多边形重心的题目大致有这么几种: 1,质量集中在顶点上.n个顶点坐标为(xi,yi),质量为mi,则重心 X ...

  6. HDU 1115(求质量均匀分布的多边形重心 物理)

    题意是给一个 n 边形,给出沿逆时针方向分布的各顶点的坐标,求出 n 边形的重心. 求多边形重心的情况大致上有三种: 一.多边形的质量都分布在各顶点上,像是用轻杆连接成的多边形框,各顶点的坐标为Xi, ...

  7. UVALive 4426 Blast the Enemy! --求多边形重心

    题意:求一个不规则简单多边形的重心. 解法:多边形的重心就是所有三角形的重心对面积的加权平均数. 关于求多边形重心的文章: 求多边形重心 用叉积搞一搞就行了. 代码: #include <ios ...

  8. HDOJ(1115)多边形重心

    Lifting the Stone http://acm.hdu.edu.cn/showproblem.php?pid=1115 题目描述:输入n个顶点(整数),求它们围成的多边形的重心. 算法:以一 ...

  9. HDU 2440、HDU 3694多边形费马点

    1.http://acm.hdu.edu.cn/showproblem.php?pid=2440   按照题意知道是一个简单的多边形即凸包,但给出的点并没有按照顺序的,所以需要自己先求出凸包,然后在用 ...

随机推荐

  1. Nginx正向代理代理http和https服务

    Nginx正向代理代理http和https服务 1. 背景需求 通过Nginx正向代理,去访问外网.可实现局域网不能访问外网的能力,以及防止在上网行为上,留下访问痕迹. 2. 安装配置 2.1安装 w ...

  2. Java中的==和equals的区别详解

    1.基础知识 (1)String x = "hello"; (2)String x = new String ("hello"); 第1种方式的工作机制是,首先 ...

  3. C++ 学习笔记(三)string 类

    在C语言中如果想要使用字符串那么有两种方法: 1.定义char型数组:char[10]; 然后将每个字符填充到对应的位置. 优点:这种方式将字符串放在内存所以每个位置都可以修改. 缺点:赋值比较麻烦, ...

  4. python日记整理

    都是自己的学习总结,要是总结的有问题大佬麻烦评价一下我好修改,谢谢 python插件插件+pycharm基本用法+markdown文本编写+jupyter notebook的基本操作汇总 一.计算机基 ...

  5. crm项目之整体内容(一)

    一.项目背景 YW公司是一家电池供应商,目前由于公司内部的需要,需要做一个CRM项目,需要每一个不同角色的员工登陆系统后处理自己的事情.其流程大致如下: 其项目包括三部分内容: 1.权限分配组件(rb ...

  6. Python9-网络编程3-day32

    解决黏包的问题 #server import socket sk = socket.socket() sk.bind(('127.0.0.1',8080)) sk.listen() conn,addr ...

  7. 枚举进程——暴力搜索内存(Ring0)

    上面说过了隐藏进程,这篇博客我们就简单描述一下暴力搜索进程. 一个进程要运行,必然会加载到内存中,断链隐藏进程只是把EPROCESS从链表上摘除了,但它还是驻留在内存中的.这样我们就有了找到它的方法. ...

  8. HDU 5044 Tree LCA

    题意: 给出一棵\(n(1 \leq n \leq 10^5)\)个节点的树,每条边和每个点都有一个权值,初始所有权值为0. 有两种操作: \(ADD1 \, u \, v \, k\):将路径\(u ...

  9. Aizu 2450 Do use segment tree 树链剖分

    题意: 给出一棵\(n(1 \leq n \leq 200000)\)个节点的树,每个节点有一个权值. 然后有\(2\)种操作: \(1 \, a \, b \, c\):将路径\(a \to b\) ...

  10. 新线程 handler

    class CalculateThread extends Thread { private Handler handler; @Override public void run() { super. ...