链接

卡了几天的破题,对于hdu的那份数据,这就一神题。。

借助极角排序,枚举以每一个点进行极角排序,然后构造两条扫描线,一个上面一个下面,两条同时走,把上线和下线的点以及上线左边的点分别统计出来,如下图

样例3:

假如现在以d为p[0],那么所有可能结果一定是他与其他点的连线所分割的平面,那么首先以de为上线,下线的角度为上线+pi,两条线始终维护着这样的关系。de的下一个点为f,di的下一个点为c ,比较一下两者需要转的角度,选取较小角度转,注意一下相同的时候的处理。

  1. #include <iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<algorithm>
  5. #include<stdlib.h>
  6. #include<vector>
  7. #include<cmath>
  8. #include<queue>
  9. #include<set>
  10. using namespace std;
  11. #define N 1010
  12. #define LL long long
  13. #define INF 0xfffffff
  14. const double eps = 1e-;
  15. const double pi = acos(-1.0);
  16. const double inf = ~0u>>;
  17. struct point
  18. {
  19. double x,y;
  20. double a;
  21. int flag;
  22. point(double x=,double y = ):x(x),y(y) {}
  23. } p[N],q[N];
  24. int tx[N],ty[N];
  25. typedef point pointt;
  26. point operator -(point a,point b)
  27. {
  28. return point(a.x-b.x,a.y-b.y);
  29. }
  30. int dcmp(double x)
  31. {
  32. if(fabs(x)<eps) return ;
  33. return x<?-:;
  34. }
  35. double cross(point a,point b)
  36. {
  37. return a.x*b.y-a.y*b.x;
  38. }
  39. double mul(point a,point b,point c)
  40. {
  41. return cross(b-a,c-a);
  42. }
  43. double dis(point a)
  44. {
  45. return sqrt(a.x*a.x+a.y*a.y);
  46. }
  47. int dot_online_in(point p,point l1,point l2)
  48. {
  49. return !dcmp(mul(p,l1,l2))&&(l1.x-p.x)*(l2.x-p.x)<eps&&(l1.y-p.y)*(l2.y-p.y)<eps;
  50. }
  51. double dot(point a,point b)
  52. {
  53. return a.x*b.x+a.y*b.y;
  54. }
  55. double Cal_Angle(point p1,point p2)
  56. {
  57. if(p1.x == p2.x && p1.y == p2.y)
  58. return -100.0;
  59. point v;
  60. v.x = p2.x - p1.x;
  61. v.y = p2.y - p1.y;
  62. if(p1.y <= p2.y)
  63. return acos(v.x/sqrt(dot(v,v)));
  64. return 2.0*pi - acos(v.x/sqrt(dot(v,v)));
  65. }
  66.  
  67. void Cal_Angle(point pp,point p[],int n)
  68. {
  69. for(int i = ; i < n; ++i)
  70. {
  71. p[i].a = Cal_Angle(pp,p[i]);
  72. }
  73. }
  74. bool cmp_angle(point p1,point p2)
  75. {
  76. return p1.a < p2.a;
  77. }
  78. int main()
  79. {
  80. int i,j,n;
  81. while(scanf("%d",&n)&&n)
  82. {
  83. int a =,b = ;
  84. for(i = ; i < n; i++)
  85. {
  86. scanf("%lf%lf%d",&p[i].x,&p[i].y,&p[i].flag);
  87. q[i] = p[i];
  88. if(p[i].flag) a++;
  89. else b++;
  90. }
  91. if(n<)
  92. {
  93. printf("%d\n",n);
  94. continue;
  95. }
  96. int ans = max(a,b);
  97. for(i = ; i < n; i++)
  98. {
  99. swap(q[i],q[]);
  100. for(j = ; j < n; j++)
  101. p[j] = q[j];
  102. Cal_Angle(p[],p,n);
  103. sort(p+,p+n,cmp_angle);
  104. for(j = n-; j > ; j--)
  105. p[j].a-=p[].a;
  106. double ani = p[].a,anj = pi+ani;
  107. int on_red = ,on_blue = ,under_red = , under_blue = ,red = ,blue = ;
  108. int g = ;
  109. while(dcmp(p[g].a-ani)==&&g<n)
  110. {
  111. p[g++].flag?on_red++:on_blue++;
  112. }
  113. int tk = n;
  114. for(j = g; j < n; j++)
  115. {
  116. if(dcmp(p[j].a-anj)>)
  117. {
  118. tk = j;
  119. break;
  120. }
  121. if(dcmp(p[j].a-anj)==)
  122. {
  123. while(dcmp(p[j].a-anj)==&&j<n)
  124. {
  125. p[j++].flag?under_red++:under_blue++;
  126. }
  127. tk = j;
  128. break;
  129. }
  130. p[j].flag?red++:blue++;
  131. }
  132. int ta = ,tb = ;
  133. p[].flag?ta++:tb++;
  134.  
  135. int k1 = red+on_red+under_red++b-blue-tb;
  136. int k2 = blue+on_blue+under_blue++a-red-ta;
  137.  
  138. ans = max(ans,max(k1,k2));
  139. if(g==n) continue;
  140.  
  141. while(tk<n)
  142. {
  143. red+=under_red,blue+=under_blue;
  144. on_red = on_blue = under_blue = under_red = ;
  145.  
  146. if(tk==n||p[tk].a-anj>p[g].a-ani)
  147. {
  148. ani = p[g].a;
  149. anj = ani+pi;
  150. while(dcmp(p[g].a-ani)==&&g<n)
  151. {
  152. p[g].flag?on_red++:on_blue++;
  153. p[g++].flag?red--:blue--;
  154. }
  155. }
  156. else
  157. {
  158. anj = p[tk].a;
  159. ani = anj-pi;
  160. while(dcmp(p[tk].a-anj)==&&tk<n)
  161. {
  162. p[tk++].flag?under_red++:under_blue++;
  163. }
  164. while(dcmp(p[g].a-ani)==&&g<n)
  165. {
  166. p[g].flag?on_red++:on_blue++;
  167. p[g++].flag?red--:blue--;
  168. }
  169. }
  170.  
  171. int k1 = red+on_red+under_red++b-blue-tb;
  172. int k2 = blue+on_blue+under_blue++a-red-ta;
  173. ans = max(ans,max(k1,k2));
  174. }
  175. }
  176. printf("%d\n",ans);
  177. }
  178. return ;
  179. }

poj2280Amphiphilic Carbon Molecules(极角排序)的更多相关文章

  1. POJ 2280 Amphiphilic Carbon Molecules 极角排序 + 扫描线

    从TLE的暴力枚举 到 13313MS的扫描线  再到 1297MS的简化后的扫描线,简直感觉要爽翻啦.然后满怀欣喜的去HDU交了一下,直接又回到了TLE.....泪流满面 虽说HDU的时限是2000 ...

  2. poj2280--Amphiphilic Carbon Molecules(扫描线+极角排序+转换坐标)

    题目链接:id=2280">点击打开链接 题目大意:给出n个点的坐标.每一个点有一个值0或者1,如今有一个隔板(无限长)去分开着n个点,一側统计0的个数,一側统计1的个数,假设点在板上 ...

  3. UVA - 1606 Amphiphilic Carbon Molecules 极角扫描法

    题目:点击查看题目 思路:这道题的解决思路是极角扫描法.极角扫描法的思想主要是先选择一个点作为基准点,然后求出各点对于该点的相对坐标,同时求出该坐标系下的极角,按照极角对点进行排序.然后选取点与基准点 ...

  4. 【极角排序、扫描线】UVa 1606 - Amphiphilic Carbon Molecules(两亲性分子)

    Shanghai Hypercomputers, the world's largest computer chip manufacturer, has invented a new class of ...

  5. UVa 1606 (极角排序) Amphiphilic Carbon Molecules

    如果,没有紫书上的翻译的话,我觉得我可能读不懂这道题.=_=|| 题意: 平面上有n个点,不是白点就是黑点.现在要放一条直线,使得直线一侧的白点与另一侧的黑点加起来数目最多.直线上的点可以看作位于直线 ...

  6. UVA 1606 Amphiphilic Carbon Molecules 两亲性分子 (极角排序或叉积,扫描法)

    任意线可以贪心移动到两点上.直接枚举O(n^3),会TLE. 所以采取扫描法,选基准点,然后根据极角或者两两做叉积比较进行排排序,然后扫一遍就好了.旋转的时候在O(1)时间推出下一种情况,总复杂度为O ...

  7. uva 1606 amphiphilic carbon molecules【把缩写写出来,有惊喜】(滑动窗口)——yhx

    Shanghai Hypercomputers, the world's largest computer chip manufacturer, has invented a new classof ...

  8. POJ 1696 Space Ant 【极角排序】

    题意:平面上有n个点,一只蚂蚁从最左下角的点出发,只能往逆时针方向走,走过的路线不能交叉,问最多能经过多少个点. 思路:每次都尽量往最外边走,每选取一个点后对剩余的点进行极角排序.(n个点必定能走完, ...

  9. Space Ant---poj1696(极角排序)

    题目链接:http://poj.org/problem?id=1696 题意:给你n个点,然后我们用一条线把它们连起来,形成螺旋状: 首先找到左下方的一个点作为起点,然后以它为原点进行极角排序,找到极 ...

随机推荐

  1. 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  /  ...  /   ...

  2. Day3~Day7(2016/1/23~2016/1/27)

    活动的生命周期:onCreate();onStart();onResume();onPause();onStop();onDestroy();onRestart(); 活动的启动模式:standard ...

  3. List<T> 添加 DataTable

    public System.Data.DataTable getDataTable() { System.Data.DataTable dt = new System.Data.DataTable() ...

  4. JMeter学习-020-JMeter 监听器之【聚合报告】错误率、吞吐量、传输速率实例计算

    上文 对聚合报告的结果字段进行了概要的讲述释义,同时对吞吐量.传输速率.分位数等进行了详细的阐述,此文针对上文中描述的吞吐量及传输速率的计算进行详细的实例计算演示. 多不闲述,直入主题! 实际操作步骤 ...

  5. c#:浅克隆和深克隆,序列化和反序列化

    一.浅克隆和深克隆(浅复制和深复制)浅克隆和深克隆最典型的应用是数据集对象DataSet的Clone和Copy方法.Clone()方法用来复制DataSet的结构,但是不复制DataSet的数据,实现 ...

  6. centos7 systemctl命令

    systemctl命令是系统服务管理器指令,它实际上将 service 和 chkconfig 这两个命令组合到一起. 实例: 启动nfs服务:systemctl start nfs-server.s ...

  7. IIS6(Win2003) 使用.net 4.0 后,默认文档失效解决方案。

    IIS6(Win2003) 使用.net framework 4.0 后,默认文档失效解决方案. 用.net framework 4.0 开发的WEB项目,但放到iis6 中无法使用默认文档,状况如下 ...

  8. MVC+EF OA观看视频记录

    搭建基本框架 创建基接口: using System; using System.Collections.Generic; using System.Linq; using System.Text; ...

  9. tapping of data 词义来源

    tapping of data 在数据交互的过程 数据被 窃听到. 例如, 网站的账户被泄露, 在用户登陆过程中, 其账号被第三方偷到. tapping 含义 看看 youdao 词典解释: n. [ ...

  10. [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 ...