poj 1696 (计算几何基础)
poj 1696 Space Ant
链接:http://poj.org/problem?id=1696
题意:在坐标轴上,给定n个点的 id 以及点的坐标(xi, yi),让你以最底端点开始,从右依次找出最外围的的点,形成一个螺旋状的图像。图形见题目例题,输出他们的 id。
思路:先找出最下面的点,然后依次为“据点”,对其他点进行极角排序,取出第一个点,以此点为“据点”,对其他未选择的点极角排序,选出排序后第一个点,……, 依此类推,取得 n 个点。复杂度(n^2*log(n))。
代码:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#define op operator
#define cp const P&
#define cn const
using namespace std; struct P{
int x, y, id;
void in() {scanf("%d %d %d", &id, &x, &y);}
P(int a=0, int b=0) : x(a), y(b) {}
P op-(cp a)cn {return P(x-a.x, y-a.y);}
bool op<(cp a)cn {return (x==a.x) ? y<a.y : x<a.x;}
int op^(P a) {return x*a.y - y*a.x;}
int cross(P a, P b) {return (a-*this) ^ (b-*this);}
int op*(P a) {return x*a.x + y*a.y;}
int dot(P a, P b) {return (a-*this) * (b-*this);}
int dis(P a) {return (x-a.x)*(x-a.x) + (y-a.y)*(y-a.y);}
}p[50], q; inline bool cmp(P a, P b) {
P v1 = a-q, v2 = b-q;
if((v1^v2) > 0) return true;
return (v1^v2) == 0 && (q.dis(a)-q.dis(b))<0;
} int ks[50], c; int main()
{
freopen("in.in", "r", stdin); int t, n, i, j;
scanf("%d", &t);
while(t--) {
scanf("%d", &n);
for(i = 0; i < n; ++i) {
p[i].in();
if(p[0].y > p[i].y) swap(p[0], p[i]);
}
c = 0;
ks[c++] = p[0].id;
q = p[0];
sort(p+1, p+n, cmp);
for(i = 1; i < n; ++i) {
ks[c++] = p[i].id;
q = p[i];
sort(p+i+1, p+n, cmp);
}
printf("%d", n);
for(i = 0; i < n; ++i) printf(" %d", ks[i]);
puts("");
}
return 0;
}
poj 1696 (计算几何基础)的更多相关文章
- poj 1696 叉积理解
Space Ant Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 3967 Accepted: 2489 Descrip ...
- nyis oj 68 三点顺序 (计算几何基础)
三点顺序 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描写叙述 如今给你不共线的三个点A,B,C的坐标,它们一定能组成一个三角形,如今让你推断A,B,C是顺时针给出的还是逆 ...
- 【POJ】1556 The Doors(计算几何基础+spfa)
http://poj.org/problem?id=1556 首先路径的每条线段一定是端点之间的连线.证明?这是个坑...反正我是随便画了一下图然后就写了.. 然后re是什么节奏?我记得我开够了啊.. ...
- 【POJ】2318 TOYS(计算几何基础+暴力)
http://poj.org/problem?id=2318 第一次完全是$O(n^2)$的暴力为什么被卡了-QAQ(一定是常数太大了...) 后来排序了下点然后单调搞了搞..(然而还是可以随便造出让 ...
- 【POJ】2653 Pick-up sticks(计算几何基础+暴力)
http://poj.org/problem?id=2653 我很好奇为什么这样$O(n^2)$的暴力能过.... 虽然说这是加了链表优化的,但是最坏不也是$O(n^2)$吗...(只能说数据太弱.. ...
- 【POJ】1269 Intersecting Lines(计算几何基础)
http://poj.org/problem?id=1269 我会说这种水题我手推公式+码代码用了1.5h? 还好新的一年里1A了---- #include <cstdio> #inclu ...
- POJ 2398 - Toy Storage - [计算几何基础题][同POJ2318]
题目链接:http://poj.org/problem?id=2398 Time Limit: 1000MS Memory Limit: 65536K Description Mom and dad ...
- POJ 2318 - TOYS - [计算几何基础题]
题目链接:http://poj.org/problem?id=2318 Time Limit: 2000MS Memory Limit: 65536K Description Calculate th ...
- POJ 1696 Space Ant 点积计算夹角
题意: 一只特别的蚂蚁,只能直走或者左转.在一个平面上,有很多株植物,这只蚂蚁每天需要进食一株,这只蚂蚁从起点为(0,miny)的点开始出发.求最多能活多少天 分析: 肯定是可以吃到所有植物的,以当前 ...
随机推荐
- day06 再谈编码 and 作业讲解
1. 小数据池,(其他语言又叫常量池) id() 查看变量的内存地址 is和== is 判断内存地址是否一致 == 判断内容是否一致 小数据池的作用: 为了快速的创建字符串对象, 可以减少内存的浪费 ...
- 228. [LeetCode] Summary Ranges
Given a sorted integer array without duplicates, return the summary of its ranges. Example 1: Input: ...
- Python序列之字符串 (str)
作者博文地址:http://www.cnblogs.com/spiritman/ Python字符串的常用操作包括以下但不限于以下操作: 字符串的替换.删除.切片.复制.连接.比较.查找.分割等 以下 ...
- PHP 函数总结
感觉对函数了解的不够深,从头到尾梳理一遍(更新中....) 1,class_exists(),interface_exists(),method_exists(),get_class(),get_pa ...
- 第四次c++作业
一,GitHub地址 https://github.com/ronghuijun/3Elevators-scheduling 二,命令行和文件读写 百度有时候有点蒙,命令行用的是D:>Eleva ...
- struts2文件上传突破2M限制
struts配置文件 <action name="upload" class="strutsFileUpload"> <result name ...
- App接口如何保证安全
微信开发或者高德地图,百度地图什么的api要使用,使用之前都需要注册一个账号,然后系统会给你一个key,然后调用api的时候把key传给服务器. 平常公司内部开发项目时,直接用mvc为app客户端提供 ...
- Apache 的知识点
apache 的官方文档 http://httpd.apache.org/docs/ Mac下如何查看Apache的版本 在终端(Terminal)中输入 apachectl -v,之后回车,结果如下 ...
- jdk&tomcat环境变量配置及同时运行多个tomcat方法
一:jdk配置 安装jdk1.7.0_51,安装过程中所有选项保持默认:最后配置 JDK的环境变量: 在“我的电脑”上点右键—>“属性”—>“高级”—>“环境变量(N)”. 1.新建 ...
- java之静态代理与动态代理
先看看静态代理是如何操作的 定义接口: public interface Person { public void sayHello(String content, int age); public ...