zoj 3871 Convex Hull(凸包)
来源:互联网 发布:table.sort 排序算法 编辑:程序博客网 时间:2024/05/08 16:10
题目链接:zoj 3871 Convex Hull
枚举每条边,计算出有多少情况下为凸包的边界,即有多少点在该边的左边。
#include <cstdio>#include <cstring>#include <cmath>#include <vector>#include <complex>#include <algorithm>using namespace std;typedef pair<int,int> pii;typedef long long ll;const double pi = 4 * atan(1);const double eps = 1e-10;inline int dcmp (double x) { if (fabs(x) < eps) return 0; else return x < 0 ? -1 : 1; }inline double getDistance (double x, double y) { return sqrt(x * x + y * y); }inline double torad(double deg) { return deg / 180 * pi; }struct Point {ll x, y;double ang;Point (ll x = 0, ll y = 0): x(x), y(y) {}void read () { scanf("%lld%lld", &x, &y); }//void write () { printf("%d %d", x, y); }bool operator < (const Point& u) const { return dcmp(x - u.x) < 0 || (dcmp(x-u.x)==0 && dcmp(y-u.y) < 0); }bool operator > (const Point& u) const { return u < *this; }bool operator == (const Point& u) const { return dcmp(x - u.x) == 0 && dcmp(y - u.y) == 0; }bool operator != (const Point& u) const { return !(*this == u); }bool operator <= (const Point& u) const { return *this < u || *this == u; }bool operator >= (const Point& u) const { return *this > u || *this == u; }Point operator + (const Point& u) { return Point(x + u.x, y + u.y); }Point operator - (const Point& u) { return Point(x - u.x, y - u.y); }Point operator * (const double u) { return Point(x * u, y * u); }Point operator / (const double u) { return Point(x / u, y / u); }double operator * (const Point& u) { return x*u.y - y*u.x; }};typedef Point Vector;const int maxn = 1005;const int mod = 998244353;int N, pow2[maxn];Point P[maxn], T[maxn * 2];ll getCross (Vector a, Vector b) { return a.x * b.y - a.y * b.x; }ll getArea (Point a, Point b, Point c) { return (getCross(b - a, c - a) % mod + mod) % mod; }inline bool cmp(const Point& a, const Point& b) { return a.ang < b.ang; }int main () {pow2[0] = 1;for (int i = 1; i < maxn; i++) pow2[i] = pow2[i-1] * 2 % mod;for (int i = 0; i < maxn; i++) pow2[i] = (pow2[i] - 1 + mod) % mod;int cas;scanf("%d", &cas);while (cas--) {scanf("%d", &N);for (int i = 0; i < N; i++) P[i].read();ll ans = 0;for (int i = 0; i < N; i++) {int sz = 0;for (int j = 0; j < N; j++) if (i != j) {T[sz] = P[j];T[sz++].ang = atan2(P[j].y-P[i].y, P[j].x-P[i].x);}for (int j = 0; j < sz; j++) {T[j+sz] = T[j];T[j+sz].ang += pi * 2;}sort(T, T + sz * 2, cmp);int r = 0;for (int j = 0; j < sz; j++) {while (T[r+1].ang - T[j].ang < pi) r++;ans = (ans + getArea(Point(0, 0), P[i], T[j]) % mod * pow2[r-j]) % mod;}}printf("%lld\n", ans);}return 0;}
0 0
- zoj 3871 Convex Hull(凸包)
- 凸包(convex hull)
- 凸包(Convex hull)
- 凸包(Convex Hull)
- ZOJ 3871 Convex Hull
- ZOJ 3871 Convex Hull(计数)
- POJ 3787 Convex Hull of Lattice Points(凸包)
- Convex hull 之 Graham_scan(凸包检测算法)
- UVA, 681Convex Hull Finding(凸包)
- Hdu 3662 3D Convex Hull(三维凸包)
- 寻找凸包 convex hull(一)
- MATLAB凸包Convex hull运算
- 凸包问题Finding the convex hull
- hdu 3662 3D Convex Hull (三维凸包 模板1)
- HDU 3662 3D Convex Hull(三维凸包表面多边形个数)
- 凸包(Convex Hull)问题的三种解法: 暴力,Graham Scan,分治
- POJ1113 Convex Hull/凸包 Graham scan算法
- 二维凸包convex hull之C++及OpenCV实现
- 树懒_移动开学笔记_day28_Fragment_ActionBar
- Reverse Integer
- 浏览器缓存机制浅析
- 读写XML
- 树懒_移动开学笔记_day28_Fragment_ActionBar思路
- zoj 3871 Convex Hull(凸包)
- 怎样让clistctrl禁止显示水平滚动条,但可以显示垂直滚动条
- swift - The Chain Responsibility pattern
- 每天读一点儿APM(PIX)代码之一:调度总线AP_Scheduler
- a链接为空时,页面跳动的解决办法
- 关于CPU CACHE工作机制的学习
- [leetcode] 67.Add Binary
- <LeetCode(Java版)>Add Two Numbers
- 无线安全Android小工具