UVA1606 Amphiphilic Carbon Molecules
2015-03-09 08:24
344 查看
选定一个点作为基点,依次求出每个点的极角并排序,虚拟出一条直线开始旋转,动态统计两侧黑白点的个数。
#include<cstdio> #include<cmath> #include<vector> #include<algorithm> #define maxn 100000+10 using namespace std; int n; struct node { int x,y,cl; double rad; node(int x=0,int y=0):x(x),y(y) {} bool operator <(const node &a)const { return rad<a.rad; } } p[maxn],st[maxn]; node operator -(const node &a,const node &b) { return node(a.x-b.x,a.y-b.y); } int Cross(const node &a,const node &b) { return (a.x*b.y-b.x*a.y); } int solve() { int maxx=0; for(int i=0; i<n; i++) { int k=0; for(int j=0; j<n; j++) if(i!=j) { p[k]=st[j]-st[i]; if(st[j].cl)//技巧性,以基点为中心对称,这样统计的黑白点就可以在一侧统计 { p[k].x=-p[k].x; p[k].y=-p[k].y; } p[k].rad=atan2(p[k].y,p[k].x); k++; } sort(p,p+k); int l=0,r=0,cnt=2; for(;l<k;l++) { if(l==r) { r=(r+1)%k; cnt++; } while(l!=r&&Cross(p[l],p[r])>=0) { r=(r+1)%k; cnt++; } cnt--; maxx=max(maxx,cnt); } } return maxx; } int main() { while(scanf("%d",&n)&&n) { for(int i=0; i<n; i++) { scanf("%d %d %d",&st[i].x,&st[i].y,&st[i].cl); } printf("%d\n",solve()); } return 0; }
相关文章推荐
- uva 1606 amphiphilic carbon molecules【把缩写写出来,有惊喜】(滑动窗口)——yhx
- UVa 1606 (极角排序) Amphiphilic Carbon Molecules
- UVA - 1606 Amphiphilic Carbon Molecules 极角扫描法
- UVa 1606 Amphiphilic Carbon Molecules——极角扫描
- uva1606 Amphiphilic Carbon Molecules
- UVa 1606 Amphiphilic Carbon Molecules (扫描法+极角排序)
- Amphiphilic Carbon Molecules UVA - 1606
- uva 1606 amphiphilic carbon molecules【把缩写写出来,有惊喜】(滑动窗口)——yhx
- UVA 1606 Amphiphilic Carbon Molecules 两亲性分子 (极角排序或叉积,扫描法)
- 【极角排序、扫描线】UVa 1606 - Amphiphilic Carbon Molecules(两亲性分子)
- UVA - 1606 Amphiphilic Carbon Molecules(极角排序+扫描法+计算几何)
- UVA 1606(p238)----Amphiphilic Carbon Molecules
- uva 1606 amphiphilic carbon molecules【把缩写写出来,有惊喜】(滑动窗口)——yhx
- uva 1606 amphiphilic carbon molecules【把缩写写出来,有惊喜】(滑动窗口)——yhx
- 例题8-6 两亲性分子(Amphiphilic Carbon Molecules, ACM/ICPC Shanghai 2004, UVa1606)
- 两亲性分子(Amphiphilic Carbon Molecules,Uva 1606)
- UVa OJ 1606 - Amphiphilic Carbon Molecules
- uva1606 Amphiphilic Carbon Molecules
- UVA - 1606 Amphiphilic Carbon Molecules : 极角扫描法 利用叉积比较极角大小
- Uva1606 Amphiphilic Carbon Molecules【例题8-6】【极角扫描法】【不懂!】