-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathCF989E.cpp
More file actions
124 lines (117 loc) · 3.58 KB
/
CF989E.cpp
File metadata and controls
124 lines (117 loc) · 3.58 KB
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
#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <deque>
#include <string.h>
#include <bitset>
#include <math.h>
using namespace std;
#define PI atan2(0, -1)
#define epsilon 0.000000001
#define INF 5000000000000000000
#define MOD 1000000007
struct Mat {
double **d;
int a, b;
Mat(){ a = b = 0; }
Mat(int x, int y){
a = x, b = y;
d = new double *[a];
for(int i = 0; i < a; i++){
d[i] = new double [b];
for(int j = 0; j < b; j++) d[i][j] = 0.0;
}
}
Mat operator+(const Mat &m) {
Mat r(a, b);
for(int i = 0; i < a; i++)
for(int j = 0; j < b; j++)
r.d[i][j] = (d[i][j]+m.d[i][j]);
return r;
}
vector<double> operator*(const vector<double> &v) {
vector<double> r(a, 0.0);
for(int i = 0; i < a; i++)
for(int j = 0; j < b; j++)
r[i] += d[i][j]*v[j];
return r;
}
Mat operator*(const Mat& m) {
Mat r(a, m.b);
for(int i = 0; i < a; i++)
for(int j = 0; j < b; j++)
for(int k = 0; k < m.b; k++)
r.d[i][k] = (r.d[i][k]+d[i][j]*m.d[j][k]);
return r;
}
Mat operator^(long long p) {
Mat r(a, a), base(*this);
for(int i = 0; i < a; i++) r.d[i][i] = 1.0;
while(p > 0){
if(p%2 == 1) r = r*base;
base = base*base;
p /= 2;
}
return r;
}
};
int N, Q;
pair<int, int> points [210];
bool seen [210][210];
vector<vector<int>> groups;
vector<int> locs [210];
Mat prob [14];
double ret;
int cross(pair<int, int> a, pair<int, int> b, pair<int, int> c){
return (a.first-b.first)*(a.second-c.second)-(a.second-b.second)*(a.first-c.first);
}
int main(){
//freopen("sort.in", "r", stdin); freopen("sort.out", "w", stdout);
ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(18);
cin >> N; memset(seen, false, sizeof(seen));
for(int i = 0; i < N; i++) cin >> points[i].first >> points[i].second;
for(int i = 0; i < N; i++)
for(int j = i+1; j < N; j++){
if(seen[i][j]) continue;
vector<int> lel; lel.push_back(i); lel.push_back(j);
for(int k = j+1; k < N; k++)
if(cross(points[i], points[j], points[k]) == 0)
lel.push_back(k);
for(int x : lel){
locs[x].push_back(groups.size());
for(int y : lel) seen[x][y] = true;
}
groups.push_back(lel);
}
prob[0] = Mat(N, N);
for(int i = 0; i < N; i++)
for(int j : locs[i])
for(int k : groups[j])
prob[0].d[i][k] += 1.0/(double)(locs[i].size())/(double)(groups[j].size());
for(int i = 1; i < 14; i++) prob[i] = prob[i-1]*prob[i-1];
cin >> Q;
for(int q = 0; q < Q; q++){
int t, m; cin >> t >> m; t--; m--; ret = 0.0;
vector<double> v(N, 0.0); v[t] = 1.0;
for(int i = 0; i < 14; i++)
if((m&(1<<i)) > 0)
v = prob[i]*v;
for(vector<int> g : groups){
double sum = 0.0;
for(int j : g) sum += v[j];
ret = max(ret, sum/(double)(g.size()));
}
cout << ret << '\n';
}
return 0;
}