poj1696Space Ant(逆时针螺旋形)
贪心做法,没次找最外面的点,也就是相对前面那条线偏转角度最小的点,除第一个点需要找到最下面的点即Y坐标最小,其余的每次进行极角排序。
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 55
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
int o[];
struct Point
{
int x,y;
Point(double x=,double y=):x(x),y(y) {}
int id;
}p[N];
int cc;
typedef Point pointt;
pointt operator + (Point a,Point b)
{
return Point(a.x+b.x,a.y+b.y);
}
pointt operator - (Point a,Point b)
{
return Point(a.x-b.x,a.y-b.y);
}
double dis(Point a)
{
return sqrt(1.0*a.x*a.x+a.y*a.y);
}
int cross(Point a,Point b)
{
return a.x*b.y-a.y*b.x;
}
int mul(Point p0,Point p1,Point p2)
{
return cross(p1-p0,p2-p0);
} bool cmp(Point a,Point b)
{
if(mul(p[cc],a,b)==)
return dis(a-p[cc])<dis(b-p[]);
else
return mul(p[cc],a,b)>;
}
int main()
{
int t,i,n;
cin>>t;
while(t--)
{
scanf("%d",&n);
for(i = ; i <= n ;i++)
{
scanf("%d%d%d",&p[i].id,&p[i].x,&p[i].y);
}
int tmp = ;
for(i = ; i <= n; i++)
if(p[tmp].y>p[i].y)
{
tmp = i;
}
swap(p[],p[tmp]);
int g = ;
o[++g] = p[].id;
cc = ;
for(i = ;i <= n; i++)
{
sort(p+i,p+n+,cmp);
o[++g] = p[i].id;
cc = i;
}
printf("%d",g);
for(i = ;i <= g; i++)
printf(" %d",o[i]);
puts("");
}
return ;
}
poj1696Space Ant(逆时针螺旋形)的更多相关文章
- Codeforces Round #593 (Div. 2)D(螺旋形模拟)
#define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;vector<int>po[100 ...
- LintCode-381.螺旋矩阵 II
螺旋矩阵 II 给你一个数n生成一个包含1-n^2的螺旋形矩阵 样例 n = 3 矩阵为 [ [ 1, 2, 3 ], [ 8, 9, 4 ], [ 7, 6, 5 ] ] 标 ...
- Spiral Matrix螺旋遍历矩阵
假定有: [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] 这样一个数组矩阵,现要求对其进行顺时针方向螺旋形从外至内地遍历,即输出: [1,2,3,6,9,8,7,4 ...
- AutoCAD中的螺旋究竟是什么螺旋?
AutoCad从很早的时候就开始提供了螺旋线的功能,它的用法相对简单,非常适合用来对等距螺旋的理论进行演练. 选择螺旋线工具,首先画出一个基准圆,再向内(或向外)移动鼠标,拖出一个旋转3个周期的螺旋. ...
- 杭电ACM分类
杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...
- 转载:hdu 题目分类 (侵删)
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...
- 错觉-Info:让你难以置信的视错觉
ylbtech-错觉-Info:让你难以置信的视错觉 1.返回顶部 1. 看下图:如果你看到舞者逆时针旋转说明你用左脑,如果看到顺时针旋转说明你用右脑思维. 据说这是耶鲁大学五年的研究成果. 下图 ...
- Atitit 常用比较复杂的图像滤镜 attilax大总结
Atitit 常用比较复杂的图像滤镜 attilax大总结 像素画滤镜 水彩油画滤镜 素描滤镜 梦幻镜 特点是中央集焦,周围景物朦化微带光晕,使人产生如入梦境的感觉.常用于拍摄婚纱.明星照,也用于其它 ...
- 炉石传说 C# 设计文档(序)
经过3个月的开发,有很多感触. 以前一直以为技术是开发成败的第一因素,现在发现,等到你代码写的时间够长,经验够丰富,什么功能都能随手完成,对于业务的分析能力变成了第一位. 炉石山寨版的BS版本用到的H ...
随机推荐
- Hibernate jar包详解
Hibernate一共包括了23个jar包,令人眼花缭乱.本文将详细讲解Hibernate每个jar包的作用,便于你在应用中根据自己的需要进行取舍. 下载Hibernate,例如2.0.3稳定版本,解 ...
- 过滤DataTable中的空数据
DataTable dt = new DataTable(tableName); for (int i = 0; i < columnsNames.Length; i++) { dt.Colum ...
- jquery的ajax向ashx传值,中文乱码问题
从网上查找了很多资料: 有在配置文件里面加如下配置 <globalization responseEncoding="utf-8" requestEncoding=" ...
- Android OnTouchListener,OnClickListener和OnLongClickListener的关系
在OnTouchListener事件里有MotionEvent.ACTION_DOWN,MotionEvent.ACTION_UP和MotionEvent.ACTION_MOVE三个事件,我们在这里只 ...
- js监控窗口高度和宽度
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/T ...
- linux下如何安装配置redis及主从配置
redis的优点:支持主从备份,操作指令丰富,支持异步的数据持久化 将 redis 安装到 /usr/local/webserver/redis 1.下载安装包 wget http://redis.g ...
- 双击Button按钮后执行的函数
在MFC中,当在用户界面拖入一个button后,双击会进入cpp文件,实现一个按钮点击的方法如: void CtestcontorlDlg::OnBnClickedButton() { : } 理解: ...
- QT笔记之QLineEdit自动补全以及控件提升
转载:http://www.cnblogs.com/csuftzzk/p/qss_lineedit_completer.html?utm_source=tuicool&utm_medium=r ...
- 有关Duilib的博客(持续更新)
1.转载:http://blog.csdn.net/LostSpeed/article/category/1896505 2.支持多线程和动画 转载:http://blog.csdn.net/Skil ...
- Eclipse如何生成jar包
Eclipse如何生成jar包 图1 右击项目Properites,选择Android,选择Is Library,然后会编译生成jar包在bin目录下.