HDU 4946 Area of Mushroom(凸包)
如果一個人能統治無窮遠處,那麼他的速度一定是最大的。除了那幾種很坑的資料,比如同一個點速度相同的兩個人。永遠都是不可能。所以你要處理出來所有速度最大的點,然後用他們構成一個凸包,你把端點的點求出來了,還得判斷一下在邊上的情況。然後頂點和在邊上的點所構成的就是可以到達無窮遠處的人。
PS:抄了芳姐的模版。。哈哈哈
Area of Mushroom
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 676 Accepted Submission(s): 120
Problem Description
Teacher Mai has a kingdom with the infinite area.
He has n students guarding the kingdom.
The i-th student stands at the position (xi,yi), and his walking speed is vi.
If a point can be reached by a student, and the time this student walking to this point is strictly less than other students, this point is in the charge of this student.
For every student, Teacher Mai wants to know if the area in the charge of him is infinite.
He has n students guarding the kingdom.
The i-th student stands at the position (xi,yi), and his walking speed is vi.
If a point can be reached by a student, and the time this student walking to this point is strictly less than other students, this point is in the charge of this student.
For every student, Teacher Mai wants to know if the area in the charge of him is infinite.
Input
There are multiple test cases, terminated by a line "0".
For each test case, the first line contains one integer n(1<=n<=500).
In following n lines, each line contains three integers xi,yi,vi(0<=|xi|,|yi|,vi<=10^4).
For each test case, the first line contains one integer n(1<=n<=500).
In following n lines, each line contains three integers xi,yi,vi(0<=|xi|,|yi|,vi<=10^4).
Output
For each case, output "Case #k: s", where k is the case number counting from 1, and s is a string consisting of n character. If the area in the charge of the i-th student isn't infinite, the i-th character is "0", else it's "1".
Sample Input
3
0 0 3
1 1 2
2 2 1
0
Sample Output
Case #1: 100
Source
#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <ctime>
#include <map>
#include <set>
#define eps 1e-9
///#define M 1000100
#define LL __int64
///#define LL long long
///#define INF 0x7ffffff
#define INF 0x3f3f3f3f
#define PI 3.1415926535898
#define zero(x) ((fabs(x)<eps)?0:x)
#define clearall(A, X) memset(A, X, sizeof(A))
using namespace std;
const int maxn = 2010;
struct point
{
int x,y;
int v,id;
point(int x = 0,int y = 0):x(x),y(y) {}
} p[maxn],ch[maxn],q[maxn],pq[maxn];
int f[maxn];
typedef point pointt;
point operator -(point a,point b)
{
return point(a.x-b.x,a.y-b.y);
}
int dcmp(double x)
{
if(fabs(x)<eps) return 0;
return x<0?-1:1;
}
int cross(point a,point b)
{
return a.x*b.y-a.y*b.x;
}
int mul(point a,point b,point c)
{
return cross(b-a,c-a);
}
double dis(point a)
{
return sqrt(a.x*a.x+a.y*a.y);
}
bool cmp(point a,point b)
{
if(mul(p[0],a,b)==0)
return dis(a-p[0])<dis(b-p[0]);
return mul(p[0],a,b)>0;
}
int graham(int n)///返回點的個數
{
int i,k =0 ,top;
if(n<2) return 0;
point tmp ;
for(i = 0; i < n ; i++)
{
if(dcmp(p[i].y-p[k].y)<0||(dcmp(p[i].y-p[k].y)==0&&dcmp(p[i].x-p[k].x)<0))
k = i;
}
swap(p[k],p[0]);
sort(p+1,p+n,cmp);
ch[0] = p[0];
ch[1] = p[1];
top = 1;
for(i = 2; i < n ; i++)
{
while(top>0&&dcmp(mul(ch[top-1],ch[top],p[i]))<=0) top--;
top++;
ch[top] = p[i];
}
return top;
}
bool cmpp(point a,point b)
{
if(a.x==b.x) return a.y<b.y;
return a.x<b.x;
}
int main()
{
int Case = 1;
int n;
while(cin >>n)
{
if(!n) break;
memset(f, 0, sizeof(f));
int Max = -INF;
for(int i = 1; i <= n; i++)
{
scanf("%d %d %d",&q[i].x, &q[i].y, &q[i].v);
q[i].id = i;
if(!q[i].v) f[i] = -2;
Max = max(Max, q[i].v);
}
for(int i = 1; i <= n; i++)
{
if(q[i].v != Max) continue;
for(int j = i+1; j <= n; j++)
{
if(q[j].x == q[i].x && q[j].y == q[i].y && q[j].v == q[i].v)
{
f[q[j].id] = -1;
f[q[i].id] = -1;
}
}
}
int t = 0;
for(int i = 1; i <= n; i++)
if(q[i].v == Max && f[q[i].id] != -2) p[t++] = q[i];
int m = graham(t);
cout<<"Case #"<<Case++<<": ";
if(m < 2)
{
for(int i = 1; i <= n; i++)
{
if(f[i] != -1 && f[i] != -2 && q[i].v == Max) cout<<1;
else cout<<0;
}
cout<<endl;
continue;
}
ch[m+1] = ch[0];
for(int i = 0; i <= m; i++) if(!f[ch[i].id]) f[ch[i].id] = 1;
for(int i = 1; i <= n; i++)
{
if(f[i] || q[i].v != Max) continue;
for(int j = 0; j <= m; j++)
if(mul(ch[j], ch[j+1], q[i]) == 0) f[i] = 1;
}
for(int i = 1; i <= n; i++)
{
if(f[i] == 1) cout<<1;
else cout<<0;
}
cout<<endl;
}
return 0;
}
相關文章
- HDU 3685 Rotational Painting(凸包+重心)AI
- HDU 4667 Building Fence(求凸包的周長)UI
- 求多邊形凸包(線性演算法)--陳氏凸包演算法--演算法
- SGU 277 Heroes(動態凸包維護)
- BZOJ3796 : Mushroom追妹紙OOM
- 斜率優化(凸包優化)DP問題acm優化ACM
- POJ 1113-Wall(凸包-Graham演算法)演算法
- 【凸包 Graham法 點集排序】poj 1113 Wall排序
- 計算幾何(一):凸包問題(Convex Hull)
- [USACO5.1] 圈奶牛Fencing the Cows /【模板】二維凸包
- 簡單的揹包問題(入門)HDU2602 HDU2546 HDU1864
- Code Area和Data Area有什麼區別
- sort_area_retained_size與sort_area_sizeAI
- 【凸包 Graham法 極角排序】poj 2007 Scrambled Polygon排序Go
- P6810 「MCOI-02」Convex Hull 凸包 題解
- 凸優化優化
- 「管理數學基礎」3.1 凸分析:凸集與凸集分離定理、Farkas引理
- Oracle 11gR2 fast recovery area = flash recovery areaOracleAST
- 凸集、凸函式定義及主要性質函式
- 為什麼凸問題的解集是凸集
- oracle Flash Revovery AreaOracle
- Oracle pending areaOracle
- UVA 10652 Board Wrapping(計算幾何基礎,求凸包)APP
- Convex Set and Convex Function凸集與凸函式Function函式
- 凸優化問題優化
- 02-凸函式函式
- 設定Flash Recovery Area
- Overview of the System Global Area (70)View
- 【Fixed Area】從SGA的Fixed Area中得到系統當前的SCN號
- The runtime data area model of JVMJVM
- LeetCode-Rectangle AreaLeetCode
- In this new Buy fifa coins? area
- ASP.NET MVC系列:AreaASP.NETMVC
- Difference between business area and profit center
- POJ 1584-A Round Peg in a Ground Hole(計算幾何-凸包、點到線段距離)
- Oracle8i中SORT_AREA_SIZE和SORT_AREA_RETAINED_SIZE的理解OracleAI
- Codeforces Gym 100286A. Aerodynamics 計算幾何 求二維凸包面積
- 03-凸優化問題優化