poj2280Amphiphilic Carbon Molecules(极角排序)
卡了几天的破题,对于hdu的那份数据,这就一神题。。
借助极角排序,枚举以每一个点进行极角排序,然后构造两条扫描线,一个上面一个下面,两条同时走,把上线和下线的点以及上线左边的点分别统计出来,如下图
样例3:
假如现在以d为p[0],那么所有可能结果一定是他与其他点的连线所分割的平面,那么首先以de为上线,下线的角度为上线+pi,两条线始终维护着这样的关系。de的下一个点为f,di的下一个点为c ,比较一下两者需要转的角度,选取较小角度转,注意一下相同的时候的处理。
- #include <iostream>
- #include<cstdio>
- #include<cstring>
- #include<algorithm>
- #include<stdlib.h>
- #include<vector>
- #include<cmath>
- #include<queue>
- #include<set>
- using namespace std;
- #define N 1010
- #define LL long long
- #define INF 0xfffffff
- const double eps = 1e-;
- const double pi = acos(-1.0);
- const double inf = ~0u>>;
- struct point
- {
- double x,y;
- double a;
- int flag;
- point(double x=,double y = ):x(x),y(y) {}
- } p[N],q[N];
- int tx[N],ty[N];
- 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 ;
- return x<?-:;
- }
- double cross(point a,point b)
- {
- return a.x*b.y-a.y*b.x;
- }
- double 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);
- }
- int dot_online_in(point p,point l1,point l2)
- {
- return !dcmp(mul(p,l1,l2))&&(l1.x-p.x)*(l2.x-p.x)<eps&&(l1.y-p.y)*(l2.y-p.y)<eps;
- }
- double dot(point a,point b)
- {
- return a.x*b.x+a.y*b.y;
- }
- double Cal_Angle(point p1,point p2)
- {
- if(p1.x == p2.x && p1.y == p2.y)
- return -100.0;
- point v;
- v.x = p2.x - p1.x;
- v.y = p2.y - p1.y;
- if(p1.y <= p2.y)
- return acos(v.x/sqrt(dot(v,v)));
- return 2.0*pi - acos(v.x/sqrt(dot(v,v)));
- }
- void Cal_Angle(point pp,point p[],int n)
- {
- for(int i = ; i < n; ++i)
- {
- p[i].a = Cal_Angle(pp,p[i]);
- }
- }
- bool cmp_angle(point p1,point p2)
- {
- return p1.a < p2.a;
- }
- int main()
- {
- int i,j,n;
- while(scanf("%d",&n)&&n)
- {
- int a =,b = ;
- for(i = ; i < n; i++)
- {
- scanf("%lf%lf%d",&p[i].x,&p[i].y,&p[i].flag);
- q[i] = p[i];
- if(p[i].flag) a++;
- else b++;
- }
- if(n<)
- {
- printf("%d\n",n);
- continue;
- }
- int ans = max(a,b);
- for(i = ; i < n; i++)
- {
- swap(q[i],q[]);
- for(j = ; j < n; j++)
- p[j] = q[j];
- Cal_Angle(p[],p,n);
- sort(p+,p+n,cmp_angle);
- for(j = n-; j > ; j--)
- p[j].a-=p[].a;
- double ani = p[].a,anj = pi+ani;
- int on_red = ,on_blue = ,under_red = , under_blue = ,red = ,blue = ;
- int g = ;
- while(dcmp(p[g].a-ani)==&&g<n)
- {
- p[g++].flag?on_red++:on_blue++;
- }
- int tk = n;
- for(j = g; j < n; j++)
- {
- if(dcmp(p[j].a-anj)>)
- {
- tk = j;
- break;
- }
- if(dcmp(p[j].a-anj)==)
- {
- while(dcmp(p[j].a-anj)==&&j<n)
- {
- p[j++].flag?under_red++:under_blue++;
- }
- tk = j;
- break;
- }
- p[j].flag?red++:blue++;
- }
- int ta = ,tb = ;
- p[].flag?ta++:tb++;
- int k1 = red+on_red+under_red++b-blue-tb;
- int k2 = blue+on_blue+under_blue++a-red-ta;
- ans = max(ans,max(k1,k2));
- if(g==n) continue;
- while(tk<n)
- {
- red+=under_red,blue+=under_blue;
- on_red = on_blue = under_blue = under_red = ;
- if(tk==n||p[tk].a-anj>p[g].a-ani)
- {
- ani = p[g].a;
- anj = ani+pi;
- while(dcmp(p[g].a-ani)==&&g<n)
- {
- p[g].flag?on_red++:on_blue++;
- p[g++].flag?red--:blue--;
- }
- }
- else
- {
- anj = p[tk].a;
- ani = anj-pi;
- while(dcmp(p[tk].a-anj)==&&tk<n)
- {
- p[tk++].flag?under_red++:under_blue++;
- }
- while(dcmp(p[g].a-ani)==&&g<n)
- {
- p[g].flag?on_red++:on_blue++;
- p[g++].flag?red--:blue--;
- }
- }
- int k1 = red+on_red+under_red++b-blue-tb;
- int k2 = blue+on_blue+under_blue++a-red-ta;
- ans = max(ans,max(k1,k2));
- }
- }
- printf("%d\n",ans);
- }
- return ;
- }
poj2280Amphiphilic Carbon Molecules(极角排序)的更多相关文章
- POJ 2280 Amphiphilic Carbon Molecules 极角排序 + 扫描线
从TLE的暴力枚举 到 13313MS的扫描线 再到 1297MS的简化后的扫描线,简直感觉要爽翻啦.然后满怀欣喜的去HDU交了一下,直接又回到了TLE.....泪流满面 虽说HDU的时限是2000 ...
- poj2280--Amphiphilic Carbon Molecules(扫描线+极角排序+转换坐标)
题目链接:id=2280">点击打开链接 题目大意:给出n个点的坐标.每一个点有一个值0或者1,如今有一个隔板(无限长)去分开着n个点,一側统计0的个数,一側统计1的个数,假设点在板上 ...
- UVA - 1606 Amphiphilic Carbon Molecules 极角扫描法
题目:点击查看题目 思路:这道题的解决思路是极角扫描法.极角扫描法的思想主要是先选择一个点作为基准点,然后求出各点对于该点的相对坐标,同时求出该坐标系下的极角,按照极角对点进行排序.然后选取点与基准点 ...
- 【极角排序、扫描线】UVa 1606 - Amphiphilic Carbon Molecules(两亲性分子)
Shanghai Hypercomputers, the world's largest computer chip manufacturer, has invented a new class of ...
- UVa 1606 (极角排序) Amphiphilic Carbon Molecules
如果,没有紫书上的翻译的话,我觉得我可能读不懂这道题.=_=|| 题意: 平面上有n个点,不是白点就是黑点.现在要放一条直线,使得直线一侧的白点与另一侧的黑点加起来数目最多.直线上的点可以看作位于直线 ...
- UVA 1606 Amphiphilic Carbon Molecules 两亲性分子 (极角排序或叉积,扫描法)
任意线可以贪心移动到两点上.直接枚举O(n^3),会TLE. 所以采取扫描法,选基准点,然后根据极角或者两两做叉积比较进行排排序,然后扫一遍就好了.旋转的时候在O(1)时间推出下一种情况,总复杂度为O ...
- uva 1606 amphiphilic carbon molecules【把缩写写出来,有惊喜】(滑动窗口)——yhx
Shanghai Hypercomputers, the world's largest computer chip manufacturer, has invented a new classof ...
- POJ 1696 Space Ant 【极角排序】
题意:平面上有n个点,一只蚂蚁从最左下角的点出发,只能往逆时针方向走,走过的路线不能交叉,问最多能经过多少个点. 思路:每次都尽量往最外边走,每选取一个点后对剩余的点进行极角排序.(n个点必定能走完, ...
- Space Ant---poj1696(极角排序)
题目链接:http://poj.org/problem?id=1696 题意:给你n个点,然后我们用一条线把它们连起来,形成螺旋状: 首先找到左下方的一个点作为起点,然后以它为原点进行极角排序,找到极 ...
随机推荐
- The index also can be used for LIKE comparisons if the argument to LIKE is a constant string that does not start with a wildcard character.
http://dev.mysql.com/doc/refman/5.7/en/index-btree-hash.html MySQL 5.7 Reference Manual / ... / ...
- Day3~Day7(2016/1/23~2016/1/27)
活动的生命周期:onCreate();onStart();onResume();onPause();onStop();onDestroy();onRestart(); 活动的启动模式:standard ...
- List<T> 添加 DataTable
public System.Data.DataTable getDataTable() { System.Data.DataTable dt = new System.Data.DataTable() ...
- JMeter学习-020-JMeter 监听器之【聚合报告】错误率、吞吐量、传输速率实例计算
上文 对聚合报告的结果字段进行了概要的讲述释义,同时对吞吐量.传输速率.分位数等进行了详细的阐述,此文针对上文中描述的吞吐量及传输速率的计算进行详细的实例计算演示. 多不闲述,直入主题! 实际操作步骤 ...
- c#:浅克隆和深克隆,序列化和反序列化
一.浅克隆和深克隆(浅复制和深复制)浅克隆和深克隆最典型的应用是数据集对象DataSet的Clone和Copy方法.Clone()方法用来复制DataSet的结构,但是不复制DataSet的数据,实现 ...
- centos7 systemctl命令
systemctl命令是系统服务管理器指令,它实际上将 service 和 chkconfig 这两个命令组合到一起. 实例: 启动nfs服务:systemctl start nfs-server.s ...
- IIS6(Win2003) 使用.net 4.0 后,默认文档失效解决方案。
IIS6(Win2003) 使用.net framework 4.0 后,默认文档失效解决方案. 用.net framework 4.0 开发的WEB项目,但放到iis6 中无法使用默认文档,状况如下 ...
- MVC+EF OA观看视频记录
搭建基本框架 创建基接口: using System; using System.Collections.Generic; using System.Linq; using System.Text; ...
- tapping of data 词义来源
tapping of data 在数据交互的过程 数据被 窃听到. 例如, 网站的账户被泄露, 在用户登陆过程中, 其账号被第三方偷到. tapping 含义 看看 youdao 词典解释: n. [ ...
- [Android Tips] 16. Update Android SDK from command-line
$ cd $ANROID_HOME $ tools/android update sdk -u -s 参数 -s --no-https : Uses HTTP instead of HTTPS (th ...