http://poj.org/problem?id=1696

极角排序是就是字面上的意思   按照极角排序

题目大意:平面上有n个点然后有一只蚂蚁他只能沿着点向左走  求最多能做多少点

分析:  其实还不知道极角排序到底是什么,   但是又好像知道一点   必须一直排序  然后一直找到最左的点就行了

  1. #include<stdio.h>
  2. #include<math.h>
  3. #include<algorithm>
  4. #include<iostream>
  5. #include<string.h>
  6. #include<stdlib.h>
  7. #include<ctype.h>
  8. #include<vector>
  9. using namespace std;
  10. #define INF 0xfffffff
  11. #define ESP 1e-8
  12. #define memset(a,b) memset(a,b,sizeof(a))
  13. #define N 2100
  14.  
  15. struct Point
  16. {
  17. double x,y;
  18. int index;
  19. Point(double x=,double y=):x(x),y(y){}
  20. Point operator - (const Point &temp)const{
  21. return Point(x-temp.x,y-temp.y);
  22. }
  23. Point operator + (const Point &temp)const{
  24. return Point(x+temp.x,y+temp.y);
  25. }
  26. int operator ^(const Point &temp)const{///求叉积
  27. double t=(x*temp.y)-(y*temp.x);
  28. if(t>ESP)
  29. return ;
  30. if(fabs(t)<ESP)
  31. return ;
  32. return -;
  33. }
  34. double operator * (const Point &temp)const{
  35. return x*temp.x+y*temp.y;
  36. }
  37. bool operator == (const Point &temp)const{
  38. return (x==temp.x)&&(y==temp.y);
  39. }
  40. }p[N];
  41.  
  42. double dist(Point a1,Point a2)
  43. {
  44. return sqrt((a1-a2)*(a1-a2));
  45. }
  46. int pos=;
  47.  
  48. int cmp(Point a1,Point a2)
  49. {
  50. int t=(a1-p[pos])^(a2-p[pos]);
  51. if(t==)
  52. return dist(p[pos],a1) < dist(p[pos],a2);
  53. else if(t<) return false;
  54. else
  55. return true;
  56. }
  57.  
  58. int main()
  59. {
  60. int T,n;
  61. scanf("%d",&T);
  62. while(T--)
  63. {
  64. scanf("%d",&n);
  65. for(int i=;i<n;i++)
  66. {
  67. scanf("%d %lf %lf",&p[i].index,&p[i].x,&p[i].y);
  68. if(p[i].y<p[].y || (p[i].y==p[].y && p[i].x<p[].x))
  69. swap(p[i],p[]);
  70. }
  71. pos=;
  72.  
  73. for(int i=;i<n;i++)
  74. {
  75. sort(p+i,p+n,cmp);
  76. pos++;
  77. }
  78. printf("%d",n);
  79. for(int i=;i<n;i++)
  80. printf(" %d",p[i].index);
  81. printf("\n");
  82. }
  83. return ;
  84. }

Space Ant--poj1696(极角排序)的更多相关文章

  1. poj 1696 Space Ant (极角排序)

    链接:http://poj.org/problem?id=1696 Space Ant Time Limit: 1000MS   Memory Limit: 10000K Total Submissi ...

  2. POJ 1696 Space Ant(极角排序)

    Space Ant Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2489   Accepted: 1567 Descrip ...

  3. Space Ant(极角排序)

    Space Ant http://poj.org/problem?id=1696 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions ...

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

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

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

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

  6. poj 1696:Space Ant(计算几何,凸包变种,极角排序)

    Space Ant Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2876   Accepted: 1839 Descrip ...

  7. poj1696 Space Ant【计算几何】

    含极角序排序模板.   Space Ant Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5334   Accepted:  ...

  8. 二维坐标系极角排序的应用(POJ1696)

    Space Ant Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3170   Accepted: 2029 Descrip ...

  9. POJ-1696 Space Ant 凸包版花式水过!

                                                         Space Ant 明天早上最后一科毛概了,竟然毫无复习之意,沉迷刷题无法自拔~~ 题意:说实 ...

  10. poj1696 Space Ant

    地址: 题目: Space Ant Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4295   Accepted: 2697 ...

随机推荐

  1. UVM挑战及概述

    UVM的调度也具有其独特的挑战,尤其是在调试的领域.其中的一些挑战如下: 1. Phase的管理:objections and synchronization 2. 线程调试 3. Tracing i ...

  2. (转)为Spring集成的Hibernate配置二级缓存

    http://blog.csdn.net/yerenyuan_pku/article/details/52896195 前面我们已经集成了Spring4.2.5+Hibernate4.3.11+Str ...

  3. CFBundleURLTypes URL scheme

    https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Ar ...

  4. HashMap Hashtable TreeMap LinkedHashMap 分析

    首先对hash的了解:就是关键字,和数据建立关系的映射. hash常用算法:假设我们中的字符有相应的内部编码,当然在实际过程中,我们不可能将所有的编码当做hash值. 平方取中法,将所得的内部编码平方 ...

  5. 【软件构造】第三章第四节 面向对象编程OOP

    第三章第四节 面向对象编程OOP 本节讲学习ADT的具体实现技术:OOP Outline OOP的基本概念 对象 类 接口 抽象类 OOP的不同特征 封装 继承与重写(override) 多态与重载( ...

  6. DFS || HDU 2181

    题意:一个规则的实心十二面体,它的 20个顶点标出世界著名的20个城市,你从一个城市出发经过每个城市刚好一次后回到出发的城市. 前20行的第i行有3个数,表示与第i个城市相邻的3个城市.第20行以后每 ...

  7. 7. 配置undo表空间

    7. 配置undo表空间 undo日志可以存储在一个或多个undo表空间中,无需存储在系统表空间中. 要为MySQL实例配置单独的undo表空间,请执行以下步骤 [重要]: 只能在初始化新MySQL实 ...

  8. 01-mysql中的数据类型

    mysql中的列数据类型:数值型.字符串类型.日期/时间类型3种 几种列类型描述使用了下述惯例:· M #表示最大显示宽度.最大有效显示宽度是255.· D #适用于浮点和定点类型,表示小数点后面的位 ...

  9. 基于flask的网页聊天室(四)

    基于flask的网页聊天室(四) 前言 接前天的内容,今天完成了消息的处理 具体内容 上次使用了flask_login做用户登录,但是直接访问login_requare装饰的函数会报401错误,这里可 ...

  10. 给Django中的url起名字

    url反转  =>reverse 1.from django.shortcuts  import  reverse 2. 利用reverse函数对URL名称进行反转  reverse(url名称 ...