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. exportfs: /mnt/demo requires fsid= for NFS export

    解决方法:/mnt/demo 10.0.1.57(fsid=0,rw,async) //加入fsid=0参数就可.

  2. vim 自动补全 颜色设置

    vim 自动补全 颜色设置 hi Pmenu ctermfg=black ctermbg=gray guibg=# hi PmenuSel ctermfg= ctermbg= guibg=# guif ...

  3. SQL数据库中各种字段类型的说明

    (1)char.varchar.text和nchar.nvarchar.ntext     char和varchar的长度都在1到8000之间,它们的区别在于char是定长字符数据,而varchar是 ...

  4. *运算和&运算

    /* &:取地址运算符 *:指针运算符(或称为间接运算符),取指针所指向的对象的内容 */ int a,b; int *pointer_1, *pointer_2; pointer_1 = & ...

  5. C#MySQL增删改查

    首先在项目中添加引用 using MySql.Data.MySqlClient; 连接字符串  private string connString="server=localhost;use ...

  6. redis cluster 配置

    #服务器192.168.56.111 192.168.56.112 192.168.56.113 计划1主2从   192.168.56.111 192.168.56.112 192.168.56.1 ...

  7. tomcat如何登录Server Status、Manager App、Host Manager

    启动tomcat后,访问127.0.0.1会进入如下页面 版权声明:本文为博主原创文章,未经博主允许不得转载. 原文地址:https://www.cnblogs.com/poterliu/p/9602 ...

  8. tp5使用外部类的三种方法

    在tp5中使用外部类的时候有三种方法 第一种就是通过composer下载,通过这种方式下载的外部类能够支持自动加载,我们只要在使用的时候use一下命名空间就可以使用了 比如:我们的tp5第四季项目要使 ...

  9. redis+PHP消息队列实现及应用

    学习视频: http://www.imooc.com/learn/852 学习笔记: https://blog.csdn.net/qq_33862644/article/details/7938564 ...

  10. 蓝桥--2n皇后问题(递归)--搬运+整理+注释

    N皇后问题: #include <iostream> #include <cmath> using namespace std; int N; ];//用来存放算好的皇后位置. ...