zoj 3871 Convex Hull(凸包)

來源:互聯網
上載者:User

標籤:

題目連結: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;}


著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

zoj 3871 Convex Hull(凸包)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.