1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
| #include <bits/stdc++.h>
#define int long long
#define repi(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,a) repi(i,0,a)
#define all(u) (u).begin(),(u).end()
#define pb push_back
#define mp make_pair
#define EPS 1e-10
#define PI acos(-1.0)
using namespace std;
typedef complex<double> P;
typedef vector<P> G;
double dot(const P& a, const P& b) { return real(conj(a)*b); }
struct L {
P a, b;
L(const P &a, const P &b) : a(a), b(b){ }
};
P projection(const L &l, const P &p) {
double t = dot(p-l.a, l.a-l.b) / norm(l.a-l.b);
return l.a + t*(l.a-l.b);
}
P reflection(const L &l, const P &p) { return p + 2.0 * (projection(l, p) - p);}
int N, ans;
P s;
G g;
bool used[10];
vector<L> mirrs;
bool input(){
cin >> N;
if(!N) return 0;
ans = 0;
g.clear();
memset(used,0,sizeof(used));
double a, b;
cin >> a >> b;
s = P(a,b);
rep(i,N){
cin >> a >> b;
g.pb(P(a,b));
}
return 1;
}
void ref_points(int cur){
L mirror = L(g[cur], g[(cur+1)%N]);
rep(j,N) if(j != cur && j != (cur + 1) % N) g[j] = reflection(mirror, g[j]);
}
void swap(P &p){
double s = p.real();
double t = p.imag();
p = P(t, s);
}
void realmax(P &p, P q){
double s = p.real();
double t = q.real();
p = P(max(s, t), p.imag());
}
void imagmin(P &p, P q){
double s = p.imag();
double t = q.imag();
p = P(p.real(), min(s, t));
}
bool ok(){
vector<P> res(2);
res[0] = P(-PI,0);
res[1] = P(0, PI);
int T = mirrs.size();
rep(i,T){
P args = P(arg(mirrs[i].a - s), arg(mirrs[i].b - s));
if(args.real() > args.imag()) swap(args);
P sect[2];
if(args.imag() - args.real() > PI + EPS) {
sect[0] = P(-PI, args.real());
sect[1] = P(args.imag(), PI);
}
else if(args.real() < 0 && args.imag() < 0){
sect[0] = P(args.real(), args.imag());
sect[1] = P(0, 0);
}
else if(args.real() < 0 && args.imag() >= 0){
sect[0] = P(args.real(), 0);
sect[1] = P(0, args.imag());
}
else {
sect[0] = P(0, 0);
sect[1] = P(args.real(), args.imag());
}
rep(i,res.size()){
realmax(res[i], sect[i]);
imagmin(res[i], sect[i]);
}
}
rep(i,res.size()) if(res[i].imag() - res[i].real() < EPS) {
res.erase(res.begin() + i, res.begin() + i + 1);
i--;
}
return res.size();
}
void dfs(){
if(mirrs.size() == N){
if(ok()) ans++;
return;
}
rep(i,N) if(!used[i]) {
used[i] = 1;
mirrs.pb(L(g[i],g[(i+1)%N]));
ref_points(i);
dfs();
ref_points(i);
mirrs.pop_back();
used[i] = 0;
}
}
int solve(){
dfs();
return ans;
}
signed main(){
while(input()){ cout << solve() << endl;}
return 0;
}
|