SHOW:
|
|
- or go back to the newest paste.
1 | #include<iostream> | |
2 | #include<map> | |
3 | #include<vector> | |
4 | #include<stack> | |
5 | #include<algorithm> | |
6 | #include<cmath> | |
7 | #include<set> | |
8 | #include<iomanip> | |
9 | #include<fstream> | |
10 | ||
11 | using namespace std; | |
12 | ||
13 | - | ifstream in("frog.in"); |
13 | + | int t = 0; |
14 | - | ofstream out("frog.out"); |
14 | + | |
15 | void dfs (vector<set<int>> &g, vector<bool> &used, vector<int> &tin, int v, bool &p) { | |
16 | - | bool check(vector<pair<long long, long long>> &v, long long w, long long h, long double k) { |
16 | + | used[v] = true; |
17 | - | long double x = 0; |
17 | + | tin[v] = t++; |
18 | - | long double y = 0; |
18 | + | for(auto u = g[v].begin(); u != g[v].end(); u++) { |
19 | - | long double wi = 0, hi = 0; |
19 | + | cout << v << ' ' << used.size() << ' ' << *u << endl; |
20 | - | long long prev_h = -1; |
20 | + | if(!used[*u]) |
21 | - | int last = -1; |
21 | + | dfs(g, used, tin, *u, p); |
22 | p = false; | |
23 | - | for(int i = 0; i < v.size(); i++) { |
23 | + | |
24 | - | wi = v[i].first * k; |
24 | + | |
25 | - | hi = v[i].second * k; |
25 | + | |
26 | - | if(prev_h == v[i].second) { |
26 | + | |
27 | - | if(x + wi <= w) |
27 | + | ifstream in("fortification.in"); |
28 | - | x += wi; |
28 | + | ofstream out("fortification.out"); |
29 | - | else { |
29 | + | |
30 | - | x = 0; |
30 | + | int n; |
31 | - | y += hi; |
31 | + | cin >> n; |
32 | vector<string> inp(n); | |
33 | - | last = 1; |
33 | + | |
34 | for(int i = 0; i < n; i++) { | |
35 | - | else { |
35 | + | cin >> inp[i]; |
36 | - | x = wi; |
36 | + | string s = ""; |
37 | - | y += hi; |
37 | + | for(int j = 0; j < 10 - inp[i].length() + 1; j++) |
38 | - | last = 2; |
38 | + | s += 'x'; |
39 | s += inp[i]; | |
40 | - | |
40 | + | inp[i] = s; |
41 | - | prev_h = v[i].second; |
41 | + | |
42 | ||
43 | vector<set<int>> g(10); | |
44 | - | return x <= w && y <= h; |
44 | + | |
45 | for(int i = 0; i < n; i++) { | |
46 | for(int j = i + 1; j < n; j++) { | |
47 | int c = 0; | |
48 | - | long long n, w, h; |
48 | + | while(c < 10 && inp[i][c] == inp[j][c]) |
49 | - | cin >> n >> w >> h; |
49 | + | c++; |
50 | if(c < 11) { | |
51 | - | vector<pair<long long, long long>> v(n); |
51 | + | g[inp[j][c] - 'a'].insert(inp[i][c] - 'a'); |
52 | - | for(int i = 0; i < n; i++) |
52 | + | |
53 | - | cin >> v[i].first >> v[i].second; |
53 | + | |
54 | } | |
55 | - | long double l = 0, r = 1e9; |
55 | + | |
56 | - | for(int k = 0; k < 100; k++) { |
56 | + | vector<bool> used(10, false); |
57 | - | long double m = (l + r) / 2.0; |
57 | + | vector<int> tin(10); |
58 | - | |
58 | + | bool p = true; |
59 | - | if(check(v, w, h, m)) |
59 | + | for(int i = 0; i < 10; i++) { |
60 | - | l = m; |
60 | + | if(!used[i]) { |
61 | - | else |
61 | + | dfs(g, used, tin, i, p); |
62 | - | r = m; |
62 | + | |
63 | } | |
64 | ||
65 | - | cout.precision(100); |
65 | + | if(p) { |
66 | - | cout << l << endl; |
66 | + | cout << "Yes" << endl; |
67 | for(int k : tin) | |
68 | cout << k << ' '; | |
69 | cout << endl; | |
70 | } | |
71 | else | |
72 | cout << "No" << endl; | |
73 | ||
74 | return 0; | |
75 | } |