我们先看每个点可能从哪些点折过来的,2^10枚举对角线是否用到。

然后再模拟折法,查看每个点是否满足要求。

恩,计算几何比较恶心,还好前几天刚写过一道更恶心的计算几何,点类直接拷过来2333。

 

  1 /**************************************************************
  2     Problem: 1074
  3     User: rausen
  4     Language: C++
  5     Result: Accepted
  6     Time:24 ms
  7     Memory:980 kb
  8 ****************************************************************/
  9  
 10 #include <cstdio>
 11 #include <cmath>
 12 #include <algorithm>
 13  
 14 using namespace std;
 15 typedef double lf;
 16  
 17 const int N = 10;
 18 const lf eps = 1e-8;
 19  
 20 int n, cnt;
 21  
 22 inline lf sqr(lf x) {
 23     return x * x;
 24 }
 25  
 26 inline int dcmp(lf x) {
 27     return fabs(x) <= eps ? 0 : (x > eps ? 1 : -1);
 28 }
 29  
 30 struct point {
 31     lf x, y;
 32     point() {}
 33     point(lf _x, lf _y) : x(_x), y(_y) {}
 34  
 35     inline point operator + (point p) {
 36         return point(x + p.x, y + p.y);
 37     }
 38     inline point operator - (point p) {
 39         return point(x - p.x, y - p.y);
 40     }
 41     inline lf operator * (point p) {
 42         return x * p.y - y * p.x;
 43     }
 44     inline lf operator % (point p) {
 45         return x * p.x + y * p.y;
 46     }
 47     inline point operator * (lf a) {
 48         return point(x * a, y * a);
 49     }
 50     inline point operator / (lf a) {
 51         return point(x / a, y / a);
 52     }
 53    
 54     inline bool operator < (const point &p) const {
 55         return dcmp(x - p.x) == 0 ? dcmp(y - p.y) < 0 : dcmp(x - p.x) < 0;
 56     }
 57     inline bool operator != (const point &p) const {
 58         return dcmp(x - p.x) || dcmp(y - p.y);
 59     }
 60     inline bool operator == (const point &p) const {
 61         return !dcmp(x - p.x) && !dcmp(y - p.y);
 62     }
 63      
 64     inline void read_in() {
 65         scanf("%lf%lf", &x, &y);
 66     }
 67     friend inline lf dis2(point p) {
 68         return sqr(p.x) + sqr(p.y);
 69     }
 70     friend inline lf dis(point p) {
 71         return sqrt(dis2(p));
 72     }
 73     friend inline lf angle(point p, point q) {
 74         return acos(p % q / dis(p) / dis(q));
 75     }
 76     friend inline point rotate(point p, lf A) {
 77         lf s = sin(A), c = cos(A);
 78       return point(p.x * c - p.y * s, p.x * s + p.y * c);
 79     }
 80 } ans[N << 10];
 81  
 82 struct line {
 83     point p, v;
 84     line() {}
 85     line(point _p, point _v) : p(_p), v(_v){}
 86 } l[N];
 87  
 88 inline point reverse(point p, line l, int f) {
 89     return l.p + rotate(p - l.p, angle(p - l.p, l.v) * 2 * f);
 90 }
 91  
 92 inline bool on_left(point p, line l) {
 93     return dcmp((p - l.p) * l.v) < 0;
 94 }
 95  
 96 inline bool on_right(point p, line l) {
 97     return dcmp((p - l.p) * l.v) > 0;
 98 }
 99  
100 void dfs(point p, int d) {
101     ans[++cnt] = p;
102     if (d == 0) return;
103     dfs(p, d - 1);
104     if (on_left(p, l[d])) dfs(reverse(p, l[d], -1), d - 1);
105 }
106  
107 inline bool check(lf x) {
108     return dcmp(x) > 0 && dcmp(x - 100) < 0;
109 }
110  
111 inline bool check(point p) {
112     return check(p.x) && check(p.y);
113 }
114  
115 inline point find(point p) {
116     int i;
117     for (i = 1; i <= n; ++i)
118         if (on_right(p, l[i])) p = reverse(p, l[i], 1);
119         else if (!on_left(p, l[i])) return point(-1, -1);
120     return p;
121 }
122  
123 int work(point p) {
124     int res = 0, i;
125     cnt = 0;
126     dfs(p, n);
127     sort(ans + 1, ans + cnt + 1);
128     cnt = unique(ans + 1, ans + cnt + 1) - ans - 1;
129     for (i = 1; i <= cnt; ++i)
130         if (check(ans[i]) && find(ans[i]) == p) ++res;
131     return res;
132 }
133  
134 int main() {
135     int i, Q;
136     point x, y;
137     scanf("%d", &n);
138     for (i = 1; i <= n; ++i) {
139         x.read_in(), y.read_in();
140         l[i] = line(x, y - x);
141     }
142     scanf("%d", &Q);
143     while (Q--) {
144         x.read_in();
145         printf("%d\n", work(x));
146     }
147     return 0;
148 }
View Code

 

posted on 2015-02-19 16:55  Xs酱~  阅读(510)  评论(0编辑  收藏  举报