hdu 3511 圆扫描线
来源:互联网 发布:中国广电网络投诉电话 编辑:程序博客网 时间:2024/05/29 11:05
hdu3511
题意
给n(50,000)个坐标系上的圆,xi,yi,ri。
这些圆相互不相交,并且不相切,只有相互无关或者包含的关系。
(这句话保证了扫描线的可行性)。
求被最深处的圆被其他圆包含了几次。
解析
扫描线学习心得
这个博客写的好,通俗易懂。
用set来维护所谓的上下事件点的关系。
优先级别高的处在前面位置。
线的优先级别的确定是根据y点的大小来判断的,y越大,优先级越高。
代码
#include <iostream>#include <cstdio>#include <cstdlib>#include <algorithm>#include <cstring>#include <cmath>#include <stack>#include <vector>#include <queue>#include <map>#include <set>#include <climits>#include <cassert>#define LL long long#define lson lo, mi, rt << 1#define rson mi + 1, hi, rt << 1 | 1using namespace std;const int maxn = 50000 + 10;const int inf = 0x3f3f3f3f;const double eps = 1e-8;//////////////////////////////const int UP = 0;const int DOWN = 1;const int IN = 0;const int OUT = 1;//////////////////////////////int nowLineX;struct Circle{ int x, y, r; int dep; void read() { scanf("%d%d%d", &x, &y, &r); dep = 0; } int getX(int tag) { if (tag == IN) return x - r; return x + r; } double getY(int tag) { double d = sqrt(r * 1.0 * r - (nowLineX - x) * 1.0 * (nowLineX - x)); if (tag == UP) return y + d; return y - d; }} circle[maxn];int lineNum;struct Line{ int x, y; int id; int tag; void read(int _x, int _y, int _id, int _tag) { x = _x; y = _y; id = _id; tag = _tag; } bool operator < (const Line &b)const { return (x < b.x) || (x == b.x && y > b.y); }} line[maxn << 1];struct Node{ int id; int tag; Node(){} Node(int _id, int _tag) { id = _id; tag = _tag; } bool operator < (const Node &b)const { double ya = circle[id].getY(tag); double yb = circle[b.id].getY(b.tag); return (ya > yb) || (ya == yb && tag < b.tag); }};set<Node> lines;set<Node>::iterator st, ed, it;void scanLine(){ lines.clear(); for (int i = 0; i < lineNum; i++) { nowLineX = line[i].x; if (line[i].tag == OUT) { lines.erase(Node(line[i].id, UP)); lines.erase(Node(line[i].id, DOWN)); } else { ///插入完毕后,返回当前插入的这个元素的迭代器 it = lines.insert(Node(line[i].id, UP)).first; st = ed = it; ed++; int id = it->id; //没有上方事件点,或者没有下方事件点 if (st == lines.begin() || ed == lines.end()) { circle[id].dep = 1; } //有上下方事件点 else { st--; //上下方事件点属于同一个圆 包含关系 if (st->id == ed->id) { circle[id].dep = circle[st->id].dep + 1; } //上下方事件点不属于同一个圆 //情况1:取上下方事件点深度大的 //情况2:上下方事件点深度相同 else { circle[id].dep = max(circle[st->id].dep, circle[ed->id].dep); } } lines.insert(Node(line[i].id, DOWN)); } }}int main(){#ifdef LOCAL freopen("in.txt", "r", stdin);#endif // LOCAL int n; while (~scanf("%d", &n)) { lineNum = 0; for (int i = 0; i < n; i++) { circle[i].read(); line[lineNum++].read(circle[i].getX(IN), circle[i].y, i, IN); line[lineNum++].read(circle[i].getX(OUT), circle[i].y, i, OUT); } sort(line, line + lineNum); scanLine(); int ans = 0; for (int i = 0; i < n; i++) { ans = max(ans, circle[i].dep); } printf("%d\n", ans); } return 0;}
0 0
- hdu 3511 圆扫描线
- 图形学复习4——光栅化(画线画圆扫描线反走样算法)
- HDU 3511扫描线
- hdu 3511
- hdu 3511 Prison Break 圆 扫描线
- hdu 3511 Prison Break
- HDU 3511 Prison Break
- HDU 4007 线扫描
- HDU 1255 扫描线
- HDU 1255 扫描线
- hdu 3642(扫描线)
- hdu 3255(扫描线)
- hdu 4052(扫描线)
- HDU 4445 扫描线
- HDU 1828 (扫描线)
- hdu 5738(扫描线)
- hdu
- hdu
- Add Binary
- [Leetcode 116, Medium] Populating Next Right Pointers in Each Node
- 如何让你的APK跑在 com.android.phone 进程
- 简单谈谈对Object C的理解
- 快速排序 归并排序
- hdu 3511 圆扫描线
- 【读书笔记】iOS-GCD-block
- Python GUI编程(Tkinter)
- POJ 1573:Robot Motion
- FLAG_ACTIVITY_CLEAR_TOP和FLAG_ACTIVITY_REORDER_TO_FRONT用法
- sql笔记
- MFC中CWnd类及其派生类对话框、消息处理、窗口操作
- arrlist
- [LeetCode]Merge Sorted Array