HDU 3685 Rotational Painting(凸包+重心)
Rotational Painting
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2378 Accepted Submission(s): 672
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.
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.
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.
Source
題目所求,給一個多邊形,問有多少種可以將多邊形放穩的方法。先求出重心,看重心對映到凸包的每兩條邊上,線上段上說明可以放。詳見程式碼。
題目地址:Rotational Painting
AC程式碼:
#include<iostream>
#include<string>
#include<cstring>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<deque>
#include<cstdio>
using namespace std;
double eps=1e-8;
const int N=50005;
struct point
{
double x,y;
} p[N],res[N],q[N];
bool mult(point sp,point ep,point op)
{
return (sp.x-op.x)*(ep.y-op.y)>=(ep.x-op.x)*(sp.y-op.y);
} //返回凸包上頂點的個數,不包括在凸包上的點
bool operator < (const point &l,const point &r)
{
return l.y<r.y||(l.y==r.y&&l.x<r.x);
}
int tubao(point pnt[], int n)
{
int i, len, top = 1;
sort(pnt, pnt + n);
if(n == 0) return 0;
res[0] = pnt[0];
if(n == 1) return 1;
res[1] = pnt[1];
if(n == 2) return 2;
res[2] = pnt[2];
for(i = 2; i < n; i ++)
{
while(top && mult(pnt[i], res[top], res[top-1])) top --;
res[++top] = pnt[i];
}
len = top;
res[++top] = pnt[n - 2];
for(i = n - 3; i >= 0; i --)
{
while(top != len && mult(pnt[i], res[top], res[top-1]))
top --;
res[++top] = pnt[i];
}
return top;
}
bool dianmul(point a,point b,point c) //c向ab線段作垂足落在ab上
{
double x1,y1,x2,y2,x3,y3,x4,y4;
x1=b.x-a.x,y1=b.y-a.y;
x2=c.x-a.x,y2=c.y-a.y;
x3=a.x-b.x,y3=a.y-b.y;
x4=c.x-b.x,y4=c.y-b.y;
if(x1*x2+y1*y2>eps&&x3*x4+y3*y4>eps) return true;
return false;
}
point gravi(point p[],int n) //求重心
{
int i;
double A=0, a;
point t;
t.x = t.y = 0;
p[n] = p[0];
for (i=0; i < n; i++)
{
a = p[i].x*p[i+1].y - p[i+1].x*p[i].y;
t.x += (p[i].x + p[i+1].x) * a;
t.y += (p[i].y + p[i+1].y) * a;
A += a;
}
t.x /= A*3;
t.y /= A*3;
return t;
}
int main()
{
int i,n,tes;
point zhong; //重心的座標
cin>>tes;
while(tes--)
{
cin>>n;
for(i=0; i<n; i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
zhong=gravi(p,n);
int len=tubao(p,n);
res[len]=res[0];
int cnt=0;
for(i=0; i<len; i++)
{
if(dianmul(res[i],res[i+1],zhong))
{
cnt++;
}
}
cout<<cnt<<endl;
}
return 0;
}
//203MS
相關文章
- HDU 4946 Area of Mushroom(凸包)OOM
- HDU 4667 Building Fence(求凸包的周長)UI
- HDU5709 : Claris Loves PaintingAI
- 求多邊形凸包(線性演算法)--陳氏凸包演算法--演算法
- SGU 277 Heroes(動態凸包維護)
- 樹的重心
- 斜率優化(凸包優化)DP問題acm優化ACM
- POJ 1113-Wall(凸包-Graham演算法)演算法
- 【凸包 Graham法 點集排序】poj 1113 Wall排序
- 計算幾何(一):凸包問題(Convex Hull)
- [USACO5.1] 圈奶牛Fencing the Cows /【模板】二維凸包
- 【圖論】樹的重心圖論
- 簡單的揹包問題(入門)HDU2602 HDU2546 HDU1864
- BZOJ3742 : PaintingAI
- The Five Colors of Chinese Painting(陳潔)AI
- Outpainting with Stable Diffusion on an infinite canvasAICanvas
- 【凸包 Graham法 極角排序】poj 2007 Scrambled Polygon排序Go
- P6810 「MCOI-02」Convex Hull 凸包 題解
- 凸優化優化
- 「管理數學基礎」3.1 凸分析:凸集與凸集分離定理、Farkas引理
- 【JAVA】多邊形重心計算Java
- Codeforces 448C. Painting FenceAI
- 凸集、凸函式定義及主要性質函式
- 為什麼凸問題的解集是凸集
- UVA 10652 Board Wrapping(計算幾何基礎,求凸包)APP
- CodeForces - 282B Painting EggsAI
- Codeforces 448C Painting Fence:分治AI
- POJ 1691 Painting A Board(dfs搜尋)AI
- Convex Set and Convex Function凸集與凸函式Function函式
- 凸優化問題優化
- 02-凸函式函式
- 深入淺出 Flutter Framework 之 PaintingContextFlutterFrameworkAIGCContext
- codeforces 651B Beautiful Paintings (想法)AI
- BEA新事件驅動型SOA,Java為重心事件Java
- POJ 1584-A Round Peg in a Ground Hole(計算幾何-凸包、點到線段距離)
- CF448C Painting Fence(遞迴+貪心)AI遞迴
- Codeforces Gym 100286A. Aerodynamics 計算幾何 求二維凸包面積
- 03-凸優化問題優化