巨人与鬼问题
来源:互联网 发布:知微科技招聘信息 编辑:程序博客网 时间:2024/04/28 02:36
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>#include <cstdlib>using namespace std;const int maxn = 110;int n, ans[maxn];struct Node { int x, y, id; double angle; void creat_angle(const Node &node) { angle = atan2(y - node.y, x - node.x); } bool operator < (const Node &node) const { return angle < node.angle; } int type() const {return id < n ? 1 : -1;}}node[maxn*2];void solve(int left, int right) { if (left >= right) return; int i; for (i = left + 1; i <= right; i++) { if (node[i].y < node[left].y || (node[i].y == node[left].y && node[i].x < node[left].x) ) { Node temp; temp = node[i]; node[i] = node[left]; node[left] = temp; } } for (i = left + 1; i <= right; i++) { node[i].creat_angle(node[left]); } sort(node + left + 1, node + right + 1); int cnt = node[left].type(); for (i = left + 1; i <= right; i++) { cnt += node[i].type(); if (!cnt) { ans[node[left].id] = node[i].id; ans[node[i].id] = node[left].id; solve(left + 1, i - 1); solve(i + 1, right); return; } }}int main(){ scanf("%d", &n); int i, len = n << 1; for (i = 0; i < len; i++) { scanf("%d %d", &node[i].x, &node[i].y); node[i].id = i; } solve(0, len - 1); for (int i = 0; i < n; i++) { printf("%d\n", ans[i] - n + 1); } return 0;}
1 0
- 巨人与鬼问题
- 巨人和鬼问题
- 巨人与鬼
- 高效算法设计_递归与分治(棋盘覆盖问题,循环日程表,巨人与鬼)
- 问题8.3.3 巨人与鬼 UVa 1411 Ants(分治)
- 凸包问题扩展 巨人和鬼 分治+递归
- 凸包问题扩展 巨人和鬼 分治+递归
- 算法竞赛入门经典 8.3.3巨人与鬼
- 算法竞赛入门经典 8.3.3 巨人与鬼
- 紫书 第8章 UVa1411 Ants 巨人与鬼
- 紫书_第八章_高效算法设计_8.3.3——巨人与鬼
- C++与C#之辩证:圣人与巨人比较
- 巨人网络宣布与华为建立研发合作伙伴关系
- 巨人网络与久游网双双否认收购传闻
- 史玉柱深圳密会马化腾:巨人与腾讯洽谈联合运营
- 巨人网络的游戏平台架构与日常管理
- 看巨人,学巨人,超巨人
- 蓝色巨人
- c++
- 删边
- 一些问答系统的资料
- LeetCode刷题【Array】 Spiral Matrix II
- 4274: 约素
- 巨人与鬼问题
- Mysql安装
- 纯CSS3鼠标滑过按钮动画过滤特效
- js 兼容性之阻止事件冒泡传递
- linux命令之----ls命令查询文件的所有者、权限、时间、大小等信息
- 一招教你最简易的自定义Dialog
- struts2基础总结
- Java TreeSet集合
- 深入理解java虚拟机读书笔记(三)垃圾收集器与内存分配策略