码迷,mamicode.com
首页 > 其他好文 > 详细

几何计算模板

时间:2015-08-16 21:01:16      阅读:86      评论:0      收藏:0      [点我收藏+]

标签:

技术分享
  1 #include <cstdio>
  2 #include <cstring>
  3 #include <algorithm>
  4 #include <cmath>
  5 #include <vector>
  6 #include <iostream>
  7 #include <cassert>
  8 
  9 using namespace std;
 10 
 11 typedef long long lld;
 12 
 13 const double EPS = 1e-9;
 14 const int MOD = 998244353;
 15 
 16 int sign(double x) {return x < -EPS ? -1 : x > EPS;}
 17 
 18 struct Point {
 19     lld x, y;
 20     Point() {}
 21     Point(const lld &x, const lld &y): x(x), y(y) {}
 22 
 23     void in() {
 24         cin >> x >> y;
 25     }
 26 
 27     bool dim() const {
 28         return x < 0 || x == 0 && y < 0;
 29     }
 30 };
 31 
 32 Point operator + (const Point &a, const Point &b) {
 33     return Point(a.x + b.x, a.y + b.y);
 34 }
 35 Point operator - (const Point &a, const Point &b) {
 36     return Point(a.x - b.x, a.y - b.y);
 37 }
 38 lld operator * (const Point &a, const Point &b) {
 39     return a.x * b.y - a.y * b.x;
 40 }
 41 bool operator < (const Point &a, const Point &b) {
 42     if (a.dim() == b.dim()) {
 43         return a * b > 0;
 44     }else {
 45         return a.dim() > b.dim();
 46     }
 47 }
 48 
 49 typedef vector<Point> Points;
 50 
 51 lld pow_mod(lld x, lld n) {
 52     lld ret = 1;
 53     while (n) {
 54         if (n & 1) ret = ret * x % MOD;
 55         n >>= 1; x = x * x % MOD;
 56     }
 57     return ret;
 58 }
 59 
 60 inline void add(int &x, int ad) {
 61     x += ad;
 62     if (x >= MOD) x -= MOD;
 63 }
 64 
 65 lld area(const Point &a, const Point &b) {
 66     return a * b;
 67 }
 68 
 69 int n, tot;
 70 lld pw2[1005];
 71 Point vec[1005];
 72 
 73 void work() {
 74     scanf("%d", &n);
 75     Points points(n);
 76     for (int i = 0; i < n; i++) {
 77         points[i].in();
 78     }
 79     int ans = 0;
 80     for (int i = 0; i < n; i++) {
 81         tot = 0;
 82         for (int j = 0; j < n; j++) {
 83             if (j == i) continue;
 84             vec[tot ++] = points[j] - points[i];
 85         }
 86         sort(vec, vec + tot);
 87         for (int j = 0; j < tot; j++) {
 88             int l = 1, r = tot - 1;    
 89             while (r >= l) {
 90                 int mid = (r + l) >> 1;
 91                 int Mid = (mid + j) % tot;
 92                 if (vec[j] * vec[Mid] > 0) {
 93                     l = mid + 1;
 94                 }else {
 95                     r = mid - 1;
 96                 }
 97             }
 98             -- l;
 99             add(ans, (area(points[i], points[i] + vec[j]) % MOD * (pw2[l] - 1) % MOD + MOD) % MOD);
100         }
101     }
102     printf("%d\n", ans);
103 }
104 
105 int main() {
106     pw2[0] = 1;
107     for (int i = 1; i <= 1000; i++) {
108         pw2[i] = 2 * pw2[i-1] % MOD;
109     }
110     int T;
111     scanf("%d", &T);
112     for (int cas = 1; cas <= T; cas++) {
113         work();
114     }
115     return 0;
116 }
View Code

 

几何计算模板

标签:

原文地址:http://www.cnblogs.com/get-an-AC-everyday/p/4734831.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!