Space Ant--poj1696(极角排序)
http://poj.org/problem?id=1696
极角排序是就是字面上的意思 按照极角排序
题目大意:平面上有n个点然后有一只蚂蚁他只能沿着点向左走 求最多能做多少点
分析: 其实还不知道极角排序到底是什么, 但是又好像知道一点 必须一直排序 然后一直找到最左的点就行了
- #include<stdio.h>
- #include<math.h>
- #include<algorithm>
- #include<iostream>
- #include<string.h>
- #include<stdlib.h>
- #include<ctype.h>
- #include<vector>
- using namespace std;
- #define INF 0xfffffff
- #define ESP 1e-8
- #define memset(a,b) memset(a,b,sizeof(a))
- #define N 2100
- struct Point
- {
- double x,y;
- int index;
- Point(double x=,double y=):x(x),y(y){}
- Point operator - (const Point &temp)const{
- return Point(x-temp.x,y-temp.y);
- }
- Point operator + (const Point &temp)const{
- return Point(x+temp.x,y+temp.y);
- }
- int operator ^(const Point &temp)const{///求叉积
- double t=(x*temp.y)-(y*temp.x);
- if(t>ESP)
- return ;
- if(fabs(t)<ESP)
- return ;
- return -;
- }
- double operator * (const Point &temp)const{
- return x*temp.x+y*temp.y;
- }
- bool operator == (const Point &temp)const{
- return (x==temp.x)&&(y==temp.y);
- }
- }p[N];
- double dist(Point a1,Point a2)
- {
- return sqrt((a1-a2)*(a1-a2));
- }
- int pos=;
- int cmp(Point a1,Point a2)
- {
- int t=(a1-p[pos])^(a2-p[pos]);
- if(t==)
- return dist(p[pos],a1) < dist(p[pos],a2);
- else if(t<) return false;
- else
- return true;
- }
- int main()
- {
- int T,n;
- scanf("%d",&T);
- while(T--)
- {
- scanf("%d",&n);
- for(int i=;i<n;i++)
- {
- scanf("%d %lf %lf",&p[i].index,&p[i].x,&p[i].y);
- if(p[i].y<p[].y || (p[i].y==p[].y && p[i].x<p[].x))
- swap(p[i],p[]);
- }
- pos=;
- for(int i=;i<n;i++)
- {
- sort(p+i,p+n,cmp);
- pos++;
- }
- printf("%d",n);
- for(int i=;i<n;i++)
- printf(" %d",p[i].index);
- printf("\n");
- }
- return ;
- }
Space Ant--poj1696(极角排序)的更多相关文章
- poj 1696 Space Ant (极角排序)
链接:http://poj.org/problem?id=1696 Space Ant Time Limit: 1000MS Memory Limit: 10000K Total Submissi ...
- POJ 1696 Space Ant(极角排序)
Space Ant Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2489 Accepted: 1567 Descrip ...
- Space Ant(极角排序)
Space Ant http://poj.org/problem?id=1696 Time Limit: 1000MS Memory Limit: 10000K Total Submissions ...
- POJ 1696 Space Ant 【极角排序】
题意:平面上有n个点,一只蚂蚁从最左下角的点出发,只能往逆时针方向走,走过的路线不能交叉,问最多能经过多少个点. 思路:每次都尽量往最外边走,每选取一个点后对剩余的点进行极角排序.(n个点必定能走完, ...
- Space Ant---poj1696(极角排序)
题目链接:http://poj.org/problem?id=1696 题意:给你n个点,然后我们用一条线把它们连起来,形成螺旋状: 首先找到左下方的一个点作为起点,然后以它为原点进行极角排序,找到极 ...
- poj 1696:Space Ant(计算几何,凸包变种,极角排序)
Space Ant Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2876 Accepted: 1839 Descrip ...
- poj1696 Space Ant【计算几何】
含极角序排序模板. Space Ant Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5334 Accepted: ...
- 二维坐标系极角排序的应用(POJ1696)
Space Ant Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 3170 Accepted: 2029 Descrip ...
- POJ-1696 Space Ant 凸包版花式水过!
Space Ant 明天早上最后一科毛概了,竟然毫无复习之意,沉迷刷题无法自拔~~ 题意:说实 ...
- poj1696 Space Ant
地址: 题目: Space Ant Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4295 Accepted: 2697 ...
随机推荐
- UVM挑战及概述
UVM的调度也具有其独特的挑战,尤其是在调试的领域.其中的一些挑战如下: 1. Phase的管理:objections and synchronization 2. 线程调试 3. Tracing i ...
- (转)为Spring集成的Hibernate配置二级缓存
http://blog.csdn.net/yerenyuan_pku/article/details/52896195 前面我们已经集成了Spring4.2.5+Hibernate4.3.11+Str ...
- CFBundleURLTypes URL scheme
https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Ar ...
- HashMap Hashtable TreeMap LinkedHashMap 分析
首先对hash的了解:就是关键字,和数据建立关系的映射. hash常用算法:假设我们中的字符有相应的内部编码,当然在实际过程中,我们不可能将所有的编码当做hash值. 平方取中法,将所得的内部编码平方 ...
- 【软件构造】第三章第四节 面向对象编程OOP
第三章第四节 面向对象编程OOP 本节讲学习ADT的具体实现技术:OOP Outline OOP的基本概念 对象 类 接口 抽象类 OOP的不同特征 封装 继承与重写(override) 多态与重载( ...
- DFS || HDU 2181
题意:一个规则的实心十二面体,它的 20个顶点标出世界著名的20个城市,你从一个城市出发经过每个城市刚好一次后回到出发的城市. 前20行的第i行有3个数,表示与第i个城市相邻的3个城市.第20行以后每 ...
- 7. 配置undo表空间
7. 配置undo表空间 undo日志可以存储在一个或多个undo表空间中,无需存储在系统表空间中. 要为MySQL实例配置单独的undo表空间,请执行以下步骤 [重要]: 只能在初始化新MySQL实 ...
- 01-mysql中的数据类型
mysql中的列数据类型:数值型.字符串类型.日期/时间类型3种 几种列类型描述使用了下述惯例:· M #表示最大显示宽度.最大有效显示宽度是255.· D #适用于浮点和定点类型,表示小数点后面的位 ...
- 基于flask的网页聊天室(四)
基于flask的网页聊天室(四) 前言 接前天的内容,今天完成了消息的处理 具体内容 上次使用了flask_login做用户登录,但是直接访问login_requare装饰的函数会报401错误,这里可 ...
- 给Django中的url起名字
url反转 =>reverse 1.from django.shortcuts import reverse 2. 利用reverse函数对URL名称进行反转 reverse(url名称 ...