ural 1207 计算几何
来源:互联网 发布:方维p2p 3.5 源码下载 编辑:程序博客网 时间:2024/06/10 16:28
1207. Median on the Plane
Time Limit: 1.0 second
Memory Limit: 16 MB
Memory Limit: 16 MB
The are N points on the plane (N is even). No three points belong to the same strait line. Your task is to select two points in such a way, that strait line they belong to divides the set of points into two equal-sized parts.
Input
First line contains one integer N (2 ≤ N ≤ 10000). Each of next N lines contains pair of integersxi, yi (−109 ≤ xi, yi ≤ 109), the coordinates of i-th point.
Output
Print the numbers of selected points.
Sample
40 01 00 11 1
1 4对于这题,首先想到的是暴搜,无疑是超时的。想了很久没有思路,最终偷窥了别人的思路,利用极角排序,思路豁然开朗。
首先找到最左下方的点p0,将剩下的按逆时针排序(相对于最左下方的点),点p0和中间的那个点mid,即所求的点。
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>using namespace std;struct Point { double x, y; int rank;}p[10009];double direction(Point p1, Point p2) { return ((p1.x-p[0].x)*(p2.y-p[0].y)-(p2.x-p[0].x)*(p1.y-p[0].y));}int cmp(Point p1, Point p2) { if (direction(p1, p2)>0) return 0; return 1;}int main(){ int i, n, k = 0; scanf("%d", &n); for (i = 0; i < n; ++i) { scanf("%lf %lf", &p[i].x, &p[i].y); p[i].rank = i+1; if (p[i].x < p[k].x || (p[i].x == p[k].x &&p[i].y < p[k].y)) k = i; } swap(p[0], p[k]); sort(p+1, p+n, cmp); printf("%d %d\n", p[0].rank, p[n/2].rank); return 0;}
- ural 1207 计算几何
- 计算几何 ural 1753
- 计算几何 ural 1874
- URAL 1436. Billboard(计算几何)
- 计算几何 ural 1207 Median on the Plane
- 计算几何 ural 1793Tray 2
- Ural-1020. Rope(简单计算几何)
- ural 1489. Points on a Parallelepiped 计算几何
- 计算几何 ural 1754. Explosion in a Pyramid
- 【解题报告】 Ural 1348 简单的计算几何
- Ural-1084. Goat in the Garden(计算几何)
- timus 1874. Football Goal URAL 解题报告 计算几何
- POJ 2606 / URAL 1502 Rabbit hunt (计算几何)
- URAL 1750 Pakhom and the Gully 计算几何+floyd
- ural 1550 Dean's Pyramid 3计算几何
- Ural 1207. Median on the Plane(计算几何)
- URAL 1849|Rabbit Hunt 2|计算几何|二分|Set
- URAL 2099 Space Invader 计算几何、卡精度、好题
- thread——MFC下Boost的线程编译错误问题
- 杭电 1019 简单数学题
- struct timeval和gettimeofday()
- 又一种design pattern —— 局部整体化设计模式
- 专注于操作系统24之boot,loader,kernel
- ural 1207 计算几何
- CSDN10大博客栏目火热评选中
- Oracle 内存 架构 详解
- 软件架构
- Lot
- No symbol table is loaded. Use the "file" command
- 好力凭借天
- 变量Map的两种方法
- Software develop Model