F - Rotational Painting

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Appoint description: 
System Crawler  (2014-11-09)

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 x i and y i representing a point of the polygon. (x i, y i) to (x i+1, y i+1) represents a edge of the polygon (1<=i<n), and (x n,y n) to (x 1, y 1) 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 <cmath>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm> using namespace std; const int maxn=60100;
const double eps=1e-10; double add(double a,double b)
{
if(abs(a+b)<eps*(abs(a)+abs(b))) return 0;
return a+b;
} struct point
{
double x,y;
point () {}
point(double x,double y) : x(x),y(y){
}
point operator + (point p){
return point(add(x,p.x),add(y,p.y));
}
point operator - (point p){
return point(add(x,-p.x),add(y,-p.y));
}
point operator * (double d){
return point(x*d,y*d);
}
double dot(point p){
return add(x*p.x,y*p.y);
}
double det(point p){
return add(x*p.y,-y*p.x);
} } pi[maxn];
int nn; bool on_seg(point p1,point p2,point q)
{
return (p1-q).det(p2-q)==0&&(p1-q).dot(p2-q)<=0;
}
point intersection(point p1,point p2,point q1,point q2)
{
return p1+(p2-p1)*((q2-q1).det(q1-p1)/(q2-q1).det(p2-p1));
}
bool cmp_x(const point& p,const point& q)
{
if(p.x!=q.x) return p.x<q.x;
return p.y<q.y;
} vector<point> convex_hull(point * ps,int n)
{
sort(ps,ps+n,cmp_x);
int k=0; //凸包的顶点数
vector<point> qs(n*2);
for(int i=0;i<n;i++){
while(k>1&&(qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1])<=0) k--;
qs[k++]=ps[i];
}
for(int i=n-2,t=k;i>=0;i--){
while(k>t&&(qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1])<=0) k--;
qs[k++]=ps[i];
}
qs.resize(k-1);
return qs;
} point gravity(point *p,int n)
{
double area=0;
point center;
center.x=0;
center.y=0; for(int i=0;i<n-1;i++){
area+=(p[i].x*p[i+1].y-p[i+1].x*p[i].y)/2;
center.x+=(p[i].x*p[i+1].y-p[i+1].x*p[i].y)*(p[i].x+p[i+1].x);
center.y+=(p[i].x*p[i+1].y-p[i+1].x*p[i].y)*(p[i].y+p[i+1].y);
} area+=(p[n-1].x*p[0].y-p[0].x*p[n-1].y)/2;
center.x+=(p[n-1].x*p[0].y-p[0].x*p[n-1].y)*(p[n-1].x+p[0].x);
center.y+=(p[n-1].x*p[0].y-p[0].x*p[n-1].y)*(p[n-1].y+p[0].y); center.x/=6*area;
center.y/=6*area; return center;
}
bool judge(point cen,point ind1,point ind2){//判断是否落在底边内
point v=ind1-ind2;
point w;w.x=v.y;w.y=-v.x;
point u=ind2-cen;
double t=w.det(u)/v.det(w);
// printf("%.8f\n",t);
if(t<1&&t>0)return true;
return false;
}
void solve()
{
vector<point> pp;
point cen;
cen=gravity(pi,nn);
pp=convex_hull(pi,nn);
int ans=0;
for(int i=0;i<pp.size();i++){
if(judge(cen,pp[i],pp[(i+1)%pp.size()])){
ans++;
}
}
printf("%d\n",ans);
return ;
} int main()
{
int T;
scanf("%d",&T);
while(T--){
scanf("%d",&nn);
for(int i=0;i<nn;i++) scanf("%lf%lf",&pi[i].x,&pi[i].y);
solve();
}
}

  

hdu 3685 10 杭州 现场 F - Rotational Painting 重心 计算几何 难度:1的更多相关文章

  1. hdu 3695 10 福州 现场 F - Computer Virus on Planet Pandora 暴力 ac自动机 难度:1

    F - Computer Virus on Planet Pandora Time Limit:2000MS     Memory Limit:128000KB     64bit IO Format ...

  2. hdu 3682 10 杭州 现场 C - To Be an Dream Architect 简单容斥 难度:1

    C - To Be an Dream Architect Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d &a ...

  3. hdu 3682 10 杭州 现场 C To Be an Dream Architect 容斥 难度:0

    C - To Be an Dream Architect Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d &a ...

  4. hdu 3687 10 杭州 现场 H - National Day Parade 水题 难度:0

    H - National Day Parade Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & % ...

  5. hdu 3699 10 福州 现场 J - A hard Aoshu Problem 暴力 难度:0

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

  6. hdu 3694 10 福州 现场 E - Fermat Point in Quadrangle 费马点 计算几何 难度:1

    In geometry the Fermat point of a triangle, also called Torricelli point, is a point such that the t ...

  7. hdu 3697 10 福州 现场 H - Selecting courses 贪心 难度:0

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

  8. hdu 3696 10 福州 现场 G - Farm Game DP+拓扑排序 or spfa+超级源 难度:0

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

  9. hdu 4771 13 杭州 现场 B - Stealing Harry Potter's Precious 暴力bfs 难度:0

    Description Harry Potter has some precious. For example, his invisible robe, his wand and his owl. W ...

随机推荐

  1. public boolean onKeyDown(int keyCode, KeyEvent event)

    @Override 2 public boolean onKeyDown(int keyCode, KeyEvent event) { 3 // TODO Auto-generated method ...

  2. django基于cors做跨域处理

    背景知识:跨域相关与cors策略 1.安装django-cors-headers pip install django-cors-headers 2.settings.py配置 INSTALLED_A ...

  3. 自动化测试中级篇——LazyAndroid UI自动化测试框架使用指南

    原文地址https://blog.csdn.net/iamhuanggua/article/details/53104345 简介   一直以来,安卓UI自动化测试都存在以下两个障碍,一是测试工具Mo ...

  4. 20155310 2016-2017-2 《Java程序设计》第七周学习总结

    20155310 2016-2017-2 <Java程序设计>第七周学习总结 教材学习内容总结 第十三章 时间与日期 认识时间与日期 •时间的度量 •GMT(格林威治标准时间):现在不是标 ...

  5. 一个免费ss网站的数据爬取过程

    一个免费ss网站的数据爬取过程 Apr 14, 2019 引言 爬虫整体概况 主要功能方法 绕过DDOS保护(Cloudflare) post中参数a,b,c的解析 post中参数a,b,c的解析 p ...

  6. logstash收集Nginx日志,转换为JSON格式

    Nginx日志处理为JSON格式,并放置在http区块: log_format json '{"@timestamp":"$time_iso8601",' '& ...

  7. 20145301赵嘉鑫《网络对抗》逆向及Bof基础

      20145301赵嘉鑫<网络对抗>逆向及Bof基础 实践目标 本次实践的对象是一个名为pwn1的linux可执行文件. 该程序正常执行流程是:main调用foo函数,foo函数会简单回 ...

  8. 20145204 《Java程序设计》第1周学习总结

    20145204 <Java程序设计>第1周学习总结 教材学习内容总结 本周经过不断的钻研课本,及看一些老师的视频,我对Java有了一个全新的认知.是的,Java和C都是一种语言,但是Ja ...

  9. [QA翻译]如何在Storm里拆分stream流?

    原文:http://stackoverflow.com/questions/19807395/how-would-i-split-a-stream-in-apache-storm 问题:我现在不清楚如 ...

  10. Gym 100712I Bahosain and Digits(开关翻转问题)

    http://codeforces.com/gym/100712/attachments 题意: 给出一串数字,每次选择连续的k个数字加上任意数(超过10就取余),最后要使得所有数字都相等,求最大的k ...