hdu 3685 多边形重心+凸包
Rotational Painting
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2498 Accepted Submission(s): 702
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.
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.
4
0 0
100 0
99 1
1 1
6
0 0
0 10
1 10
1 1
10 1
10 0
3
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 多边形重心+凸包的更多相关文章
- hdu 1115(多边形重心问题)
Lifting the Stone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- 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 ...
- hdu 3685 10 杭州 现场 F - Rotational Painting 重心 计算几何 难度:1
F - Rotational Painting Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & % ...
- hdu 1115:Lifting the Stone(计算几何,求多边形重心。 过年好!)
Lifting the Stone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- hdu 1115(计算多边形重心)
题意:已知一多边形没有边相交,质量分布均匀.顺序给出多边形的顶点坐标,求其重心. 分析: 求多边形重心的题目大致有这么几种: 1,质量集中在顶点上.n个顶点坐标为(xi,yi),质量为mi,则重心 X ...
- HDU 1115(求质量均匀分布的多边形重心 物理)
题意是给一个 n 边形,给出沿逆时针方向分布的各顶点的坐标,求出 n 边形的重心. 求多边形重心的情况大致上有三种: 一.多边形的质量都分布在各顶点上,像是用轻杆连接成的多边形框,各顶点的坐标为Xi, ...
- UVALive 4426 Blast the Enemy! --求多边形重心
题意:求一个不规则简单多边形的重心. 解法:多边形的重心就是所有三角形的重心对面积的加权平均数. 关于求多边形重心的文章: 求多边形重心 用叉积搞一搞就行了. 代码: #include <ios ...
- HDOJ(1115)多边形重心
Lifting the Stone http://acm.hdu.edu.cn/showproblem.php?pid=1115 题目描述:输入n个顶点(整数),求它们围成的多边形的重心. 算法:以一 ...
- HDU 2440、HDU 3694多边形费马点
1.http://acm.hdu.edu.cn/showproblem.php?pid=2440 按照题意知道是一个简单的多边形即凸包,但给出的点并没有按照顺序的,所以需要自己先求出凸包,然后在用 ...
随机推荐
- idea spring boot启动项目上面有红色叉
一打开IDEA,在启动debug项目有一个红色叉如下图 因为打开项目可以主项目的包没有加载进来,解决办法就是右击项目->maven->Reimport 就搞定了..
- 【胎教】做AI的基础,开始学习。
昨天,找了博导,他给我聊了一下暑假任务.现总结如下: 1. 周志华, 机器学习: 2. GoodFellow,深度学习: 3. 曾更生,*****医学图像处理: 4. cs231n,公式推导,课后习题 ...
- Bootstrap 标签
本章将讲解bootstrap标签,标签可用于计数,提示和页面上其它的标记显示.使用class.laber来显示标签,如下面的实例所示 <!DOCTYPE html><html> ...
- javascript原型继承圣杯模式
javascript纯面向对象开发需要使用到的一个模式,来对对象之间原型继承做中间层代理避免重复继承与代码杂乱 <!DOCTYPE html> <html lang="en ...
- 【Machine Learning is Fun!】1.The world’s easiest introduction to Machine Learning
Bigger update: The content of this article is now available as a full-length video course that walks ...
- deque 用法
引用博客:https://blog.csdn.net/zyq522376829/article/details/46801973 下面是那位大佬写的的笔记整理~~~~ deque - 双向队列 1.构 ...
- 【动态规划】bzoj1939: [Croatian2010] Zuma
隐约记得类似的一道JSOI祖玛……然后好像这题不能够把珠子合并成一段?或许是因为这里珠子碰在一起之后可以不消除? Description 有一行 N 个弹子,每一个都有一个颜色.每次可以让超过 K 个 ...
- python——全局变量&局部变量
>>> count = 5 >>> def function(): count = 10 print(10) >>> function() 10 ...
- 02_ThreadLocal语法与源码分析
文章导读: 早在JDK 1.2的版本中就提供Java.lang.ThreadLocal,ThreadLocal为解决多线程程序的并发问题提供了一种新的思路.使用这个工具类可以很简洁地编写出优美的多线程 ...
- mysql update连表
UPDATE price_air_item t1 LEFT JOIN order_item t2 ON t1.ORDER_ITEM_ID = t2.ORDER_ITEM_ID SET t1.BUYER ...