sgu253:Theodore Roosevelt(扫描线)
来源:互联网 发布:为什么淘宝上苹果便宜 编辑:程序博客网 时间:2024/05/19 12:13
题目大意:
分析:
AC code:
#include <cstdio>#include <cmath>#include <map>#include <algorithm>#define cx first#define cy second#define mp make_pair#define eps 1e-8#define is_zero(p) ((p) >= -eps && (p) <= eps)typedef double DB;using namespace std;const int MAXN = 1e5+9;const int MAXM = 1e5+9;int n, m, k;map< pair<int,int>,int > Map;struct pot{ DB x, y; pot(DB tx=0, DB ty=0):x(tx),y(ty){} friend bool operator < (const pot &a, const pot &b) { return a.x < b.x-eps || (is_zero(a.x-b.x) && a.y < b.y-eps); }}cvx[MAXN], other[MAXN];int pre[MAXN][2], suf[MAXN][2];pair<pot, int> node[MAXN+MAXM];int sign(DB x){ if(x < -eps) return -1; else return x > eps; }DB fx(const pot &a, const pot &b, DB p){ DB ret; if(is_zero(b.x-a.x)) return 1e10; ret = (p-a.x)/(b.x-a.x)*(b.y-a.y)+a.y; return ret;}void make_pre(int l, int r){ int now = r; while(now != l) { pre[now][0] = now%n+1; suf[now%n+1][0] = now; now = now%n+1; } now = r; while(now != l) { pre[now][1] = (now-2+n)%n+1; suf[(now-2+n)%n+1][1] = now; now = (now-2+n)%n+1; }}int main(){ #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif scanf("%d%d%d", &n, &m, &k); int ru = 0, ld = 0, tot = 0; for(int i = 1; i <= n; ++i) { int x, y; scanf("%d%d", &x, &y); cvx[i] = pot(x, y); node[++tot] = mp(cvx[i], i); Map[mp(x, y)] = i; if(!ru || cvx[ru] < cvx[i]) ru = i; if(!ld || cvx[i] < cvx[ld]) ld = i; } make_pre(ld, ru); int sum = 0; for(int i = 1; i <= m; ++i) { int x, y; scanf("%d%d", &x, &y); other[i] = pot(x, y); if(Map.find(mp(x, y)) != Map.end()) sum++; else node[++tot] = mp(other[i], 0); } sort(node+1, node+n+m+1); bool in = false; int up, down; for(int i = 1; i <= n+m; ++i) { int id = node[i].cy; pot now = node[i].cx; if(!id) { if(in) { DB h1 = fx(cvx[up], cvx[suf[up][0]], now.x), h2 = fx(cvx[down], cvx[suf[down][1]], now.x); if(h1 > 1e9) {if(sign(cvx[suf[up][0]].y-now.y) >= 0) sum++;} else if(h2 > 1e9) {if(sign(cvx[suf[down][1]].y-now.y) >= 0) sum++;} else if(sign(now.y-h2) >= 0 && sign(h1-now.y) >= 0) sum++; } } else { if(id == ld) in = true, up = down = id; else { if(id == ru) break; if(pre[id][0] == up) up = id; else down = id; } } } if(sum >= k) puts("YES"); else puts("NO"); #ifndef ONLINE_JUDGE fclose(stdin); fclose(stdout); #endif return 0; }
0 0
- sgu253:Theodore Roosevelt(扫描线)
- SGU 253. Theodore Roosevelt
- SGU 253. Theodore Roosevelt
- sgu-253 Theodore Roosevelt
- sgu Theodore Roosevelt【判断点是否在凸多边形内模板】
- SAT作文素材Eleanor Roosevelt
- 扫描线
- 扫描线
- 扫描线
- 扫描线
- 扫描线
- 扫描线
- 多边形扫描线算法
- HDU 4007 线扫描
- 线段树[扫描线]
- HDU 3511扫描线
- CF286D 扫描线+STL
- poj1151--Atlantis--扫描线
- 常见算法题:判断表达式括号是否匹配
- Objective-c的内存管理MRC与ARC
- android/java遍历拷贝文件和删除文件
- HDU 折线分割平面
- java中的匿名内部类总结
- sgu253:Theodore Roosevelt(扫描线)
- 基于注解的Mybatis mapper 接口注意事项
- MongoDB 介绍、安装、搭建简单的 MongoDB 服务器
- latch free 等待事件说明
- Mybatis-spring整合源码解析
- IOS 基于APNS消息推送原理与实现(JAVA后台)
- 【c++】智能指针
- Spring工作原理
- [hdu]Bone Collector