POJ 1696 Space Ant 极角排序(叉积的应用)
题目大意:给出n个点的编号和坐标,按逆时针方向连接着n个点,按连接的先后顺序输出每个点的编号。
题目思路:Cross(a,b)表示a,b的叉积,若小于0:a在b的逆时针方向,若大于0a在b的顺时针方向。每次都sort一下,找出在当前点逆时针方向的最远的点。数据很小O(N*N*log(N))的复杂度0s AC了……
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#define INF 0x3f3f3f3f
#define MAX 100005 using namespace std; int n,pos,ans[MAX]; struct node
{
int id,x,y;
}point[MAX]; int Dist(int x1,int y1,int x2,int y2)
{
return sqrt((x1-x2)*(x1-x2)*1.0 + (y1-y2)*(y1-y2)*1.0);
} int Cross(int x1,int y1,int x2,int y2,int x3,int y3)
{
return (x1-x2)*(y1-y3)-(x1-x3)*(y1-y2);
} bool cmp(struct node A,struct node B)
{
int op=Cross(point[pos].x,point[pos].y,A.x,A.y,B.x,B.y);
if(op>)
return true;
else if(op== && Dist(point[pos].x,point[pos].y,A.x,A.y)<Dist(point[pos].x,point[pos].y,B.x,B.y))
return true;
return false;
} int main()
{
int T,cnt;
scanf("%d",&T);
while(T--)
{
pos=;
cnt=;
memset(ans,,sizeof(ans));
scanf("%d",&n);
scanf("%d%d%d",&point[].id,&point[].x,&point[].y);
for(int i=;i<n;i++)
{
scanf("%d%d%d",&point[i].id,&point[i].x,&point[i].y);
if(point[i].y < point[].y)//找出起点:左下方的点
swap(point[],point[i]);
else if(point[i].y==point[].y && point[i].x < point[].x)
swap(point[],point[i]);
}
sort(point,point+n,cmp);
ans[cnt++]=point[pos++].id;
for(int i=;i<n;i++)
{
sort(point+i,point+n,cmp);
ans[cnt++]=point[pos++].id;
}
printf("%d ",cnt);
for(int i=;i<cnt;i++)
printf("%d%c",ans[i],i==cnt-?'\n':' ');
}
return ;
}
POJ 1696 Space Ant 极角排序(叉积的应用)的更多相关文章
- poj 1696 Space Ant 极角排序
#include<cstdio> #include<cstring> #include<cmath> #include<iostream> #inclu ...
- poj 1696 Space Ant(模拟+叉积)
Space Ant Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 3840 Accepted: 2397 Descrip ...
- 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 ...
- poj 1696:Space Ant(计算几何,凸包变种,极角排序)
Space Ant Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2876 Accepted: 1839 Descrip ...
- POJ 1696 Space Ant 【极角排序】
题意:平面上有n个点,一只蚂蚁从最左下角的点出发,只能往逆时针方向走,走过的路线不能交叉,问最多能经过多少个点. 思路:每次都尽量往最外边走,每选取一个点后对剩余的点进行极角排序.(n个点必定能走完, ...
- 2018.07.04 POJ 1696 Space Ant(凸包卷包裹)
Space Ant Time Limit: 1000MS Memory Limit: 10000K Description The most exciting space discovery occu ...
- POJ 1696 Space Ant 卷包裹法
Space Ant Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 3316 Accepted: 2118 Descrip ...
- POJ 1696 Space Ant(点积的应用)
Space Ant 大意:有一仅仅蚂蚁,每次都仅仅向当前方向的左边走,问蚂蚁走遍全部的点的顺序输出.開始的点是纵坐标最小的那个点,開始的方向是開始点的x轴正方向. 思路:从開始点開始,每次找剩下的点中 ...
随机推荐
- php遍历目录下文件,并读取内容
<?php echo "<h2>遍历目录下文件,并读取内容</h2><br>\n"; function listDir($dir) { i ...
- Java 序列化 JDK序列化总结
Java 序列化 JDK序列化总结 @author ixenos Java序列化是在JDK 1.1中引入的,是Java内核的重要特性之一.Java序列化API允许我们将一个对象转换为流,并通过网络发送 ...
- javabean+servlet+jsp实现分页
前端实现用ligerUI实现分页,感觉用框架确实简单,闲着无聊,模拟着liger的分页界面实现了一遍(只要是功能,样式什么无视) 这里用基础的三层架构+servlet+jsp实现,思路很简单,把所有分 ...
- sendUserActionEvent() mView== null after clicking on button
this is not a problem related to your code, but related to S4 android version. Same question has bee ...
- php 中文转拼音首字母问题
<?php /* 中文汉字转拼音首字母的PHP简易实现方法. 要求: 只能是GB2312码表里面中文字符 转换得到字符串对应的拼音首字母大写. 用法: echo zh2py::conv('Chi ...
- 图片验证码自动识别,使用tess4j进行验证码自动识别(java实现)
1.下载tess4j依赖的jar包,maven中央库地址:<dependency> <groupId>net.sourceforge.tess4j< ...
- 在eclipse中生成实体类
1.在eclipse的windows中选中preferences在查询框中输入driver definition 2.点击add在Name/type中选中mysql jdbc driver 5.1然后 ...
- Sub Lime Text
Sub Lime Text License -– BEGIN LICENSE -– Andrew Weber Single User License EA7E-855605 813A03DD 5E4A ...
- 深入了解——CSS3新增属性
CSS3 选择器(Selector) 写过 CSS 的人应该对 CSS 选择器不陌生,我们所定义的 CSS 属性之所以能应用到相应的节点上,就是因为 CSS 选择器模式.参考下述代码: 清单 1. C ...
- 菜鸟进阶——grunt
为保证作者版权在此声明本文部分摘自 http://yujiangshui.com/grunt-basic-tutorial/ 另,参考文章 http://www.tuicool.com/artic ...