UVa 1606 Amphiphilic Carbon Molecules——极角扫描
2017-06-03 10:51
337 查看
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <cmath> using namespace std; const int maxn = 1010; struct Node { int x, y, col; double rad; bool operator < (const Node &node) { return rad < node.rad; } }node[maxn], tnode[maxn]; bool cross(int x1, int y1, int x2, int y2) { return (x1 * y2 - x2 * y1) >= 0; } int main() { int n; while (scanf("%d", &n) == 1 && n) { for (int i = 0; i < n; i++) { scanf("%d %d %d", &node[i].x, &node[i].y, &node[i].col); } if (n <= 3) { printf("%d\n", n); continue; } int ans = 0; for (int i = 0; i < n; i++) { int k = 0; for (int j = 0; j < n; j++) { if (j == i) continue; tnode[k].x = node[j].x - node[i].x; tnode[k].y = node[j].y - node[i].y; tnode[k].col = node[j].col; if (tnode[k].col) { tnode[k].x = -tnode[k].x, tnode[k].y = -tnode[k].y; } tnode[k].rad = atan2(tnode[k].y, tnode[k].x); k++; } sort(tnode, tnode + k); int L = 0, R = 0, cnt = 1; while (L < k) { if (R == L) { R = (R + 1) % k; cnt++; } while (R != L && cross(tnode[L].x, tnode[L].y, tnode[R].x, tnode[R].y)) { R = (R + 1) % k; cnt++; } ans = max(ans, cnt); L++, cnt--; } } printf("%d\n", ans); } return 0; }
相关文章推荐
- 【极角排序、扫描线】UVa 1606 - Amphiphilic Carbon Molecules(两亲性分子)
- UVa 1606 Amphiphilic Carbon Molecules (扫描法+极角排序)
- UVA - 1606 Amphiphilic Carbon Molecules : 极角扫描法 利用叉积比较极角大小
- UVA - 1606 Amphiphilic Carbon Molecules 极角扫描法
- Uva1606 Amphiphilic Carbon Molecules【例题8-6】【极角扫描法】【不懂!】
- uva1606 Amphiphilic Carbon Molecules
- UVA1606 Amphiphilic Carbon Molecules
- Amphiphilic Carbon Molecules UVA - 1606
- 例题8-6 两亲性分子(Amphiphilic Carbon Molecules, ACM/ICPC Shanghai 2004, UVa1606)
- uva1606 Amphiphilic Carbon Molecules
- UVa 1606 (极角排序) Amphiphilic Carbon Molecules
- uva 1606 amphiphilic carbon molecules【把缩写写出来,有惊喜】(滑动窗口)——yhx
- UVA 1606(p238)----Amphiphilic Carbon Molecules
- uva 1606 amphiphilic carbon molecules【把缩写写出来,有惊喜】(滑动窗口)——yhx
- uva 1606 amphiphilic carbon molecules【把缩写写出来,有惊喜】(滑动窗口)——yhx
- UVA 1606 Amphiphilic Carbon Molecules 两亲性分子 (极角排序或叉积,扫描法)
- UVA - 1606 Amphiphilic Carbon Molecules(极角排序+扫描法+计算几何)
- UVa OJ 1606 - Amphiphilic Carbon Molecules
- uva 1606 amphiphilic carbon molecules【把缩写写出来,有惊喜】(滑动窗口)——yhx
- 两亲性分子(Amphiphilic Carbon Molecules,Uva 1606)