hdu 3685 10 杭州 现场 F - Rotational Painting 重心 计算几何 难度:1
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
System Crawler (2014-11-09)
Description
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
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
Sample Input
4
0 0
100 0
99 1
1 1
6
0 0
0 10
1 10
1 1
10 1
10 0
Sample Output
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的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- hdu 3687 10 杭州 现场 H - National Day Parade 水题 难度:0
H - National Day Parade Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & % ...
- 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 ...
- 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 ...
- hdu 3697 10 福州 现场 H - Selecting courses 贪心 难度:0
Description A new Semester is coming and students are troubling for selecting courses. Students ...
- 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 ...
- 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 ...
随机推荐
- Python开发【整理笔记】
回顾笔记 学python半年,新知识不断填充,之前学的东西也忘的差不多,整理下笔记,把重点再加深下印象,算是读书拾遗吧.... 1.类继承.新式类.经典类 首先,新式类.经典类的概念只存在于Pytho ...
- 巧用Salt,实现CMDB配置自动发现
随着互联网+新形势的发展,越来越多的企业步入双态(稳敏双态)IT时代,信息化环境越来越复杂,既有IOE三层架构,也有VCE.Openstack等云虚拟化架构和互联网化的分布式大数据架构.所以,企业急需 ...
- Git学习-->关于Jenkins编译时候,如何获取Git分支的当前分支名?
一.背景 因为代码都迁移到了Gitlab,所以Jenkins编译的时候我们都需要将之前的SVN信息换成现在的Git信息.最近编译一个Lib库的时候,因为团队规定上传Release版本的AAR到Mave ...
- zcash 的资料
我的比特币使用的是 electrum 2.9.3 版本.我的zcash用的是 jaxx 1.2 版. zcash又叫zec,可以在 bithumb (韩国的) 平台上进行交易zcash. zcash ...
- Flask系列之源码分析(一)
目录: 涉及知识点 Flask框架原理 简单示例 路由系统原理源码分析 请求流程简单源码分析 响应流程简单源码分析 session简单源码分析 涉及知识点 1.装饰器 闭包思想 def wapper( ...
- postman设置环境变量,字段值经过json转换后数值字节长度超过上限的问题
在使用Tests进行环境变量的设置时,遇到这么一种情况,在返回的responseBody中的userId字段,字段返回的是数值类型,再经过json转换之后,发现保存的值跟接口返回的值不一致:如下图: ...
- 5.4 Components -- Wrapping Content in A Component(在组件中包裹内容)
1.有时候,你可能希望定义一个模板,它包裹其他模板提供的内容. 例如,假设我们创建一个blog-post模板,我们可以使用它来展现一个blog post: app/components/blog-po ...
- 怎样使用CSS设置文字与文字间距距离?
[文字与文字间距距离,字与字距离间距CSS如何设置?]如果你也遇到W3Cschool用户唐婷大小姐类似的问题不妨也到W3Cschool编程问答进行提问. 对于使用CSS解决字间距的方法W3Cschoo ...
- in `connect': SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (OpenSSL::SSL::SSLError)
最近在用ruby的一些库的时候,总是出现这个错误. 在使用net/imap库的时候,或者net/http库(主要是用到了https,https是用了ssl) 的时候,具体如下: 错误提示:E:/Rub ...
- Redis在Linux下的安装与配置
Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value数据库,并提供多种语言的API. Redis是 NoSQL技术阵营中的一员. 说到NoSQL, ...