2019-2020 ICPC Northwestern European Regional Programming Contest (NWERC 2019)
虽然咕咕队友来了,但是题目好难,自闭
题目连接:https://codeforces.com/gym/102500
A:
solver:czq、zyh
1 /* basic header */ 2 #include <bits/stdc++.h> 3 /* define */ 4 #define ll long long 5 #define pb emplace_back 6 #define mp make_pair 7 #define eps 1e-8 8 #define lson (curpos<<1) 9 #define rson (curpos<<1|1) 10 /* namespace */ 11 using namespace std; 12 /* header end */ 13 14 const int maxn = 1e6 + 10; 15 int n, week, score[maxn]; 16 set<pair<int, ll>> scoreInfo[maxn]; // 以分数为下标,first是人的编号,second是 17 set<int> scores; 18 ll __rank[maxn]; 19 double ans[maxn]; 20 21 void init() { 22 scores.insert(0); 23 for (int i = 1; i <= n; i++) scoreInfo[0].insert(mp(i, 0)); 24 } 25 26 int main() { 27 scanf("%d%d", &n, &week); 28 init(); 29 for (int i = 1; i <= week; i++) { 30 int numOfPeople; scanf("%d", &numOfPeople); 31 if (!numOfPeople) { 32 int before = 0; 33 for (auto j : scores) { 34 int i = -j; 35 __rank[i] += before + 1; 36 before += scoreInfo[i].size(); 37 } 38 continue; 39 } 40 while (numOfPeople--) { 41 int currNum; scanf("%d", &currNum); 42 int currManScore = score[currNum]; // sc是当前人的分数 43 auto it = scoreInfo[currManScore].upper_bound(mp(currNum, -1)); 44 scoreInfo[currManScore + 1].insert(mp(currNum, it->second + __rank[currManScore] - __rank[currManScore + 1])); 45 scoreInfo[currManScore].erase(it); 46 score[currNum]++; 47 if (scores.count(-score[currNum]) == 0) scores.insert(-score[currNum]); 48 if (scoreInfo[currManScore].empty()) scores.erase(scores.find(-currManScore)); 49 } 50 int before = 0; 51 for (auto j : scores) { // 从高到低处理分数 52 int i = -j; 53 __rank[i] += before + 1; 54 before += scoreInfo[i].size(); 55 } 56 } 57 for (auto j : scores) { 58 int i = -j; 59 for (auto p : scoreInfo[i]) ans[p.first] = 1.0 * (p.second + __rank[i]) / week; 60 } 61 for (int i = 1; i <= n; i++) printf("%.12f\n", ans[i]); 62 return 0; 63 }
C:
solver:lzh
1 #include <bits/stdc++.h> 2 using namespace std; 3 #define ff first 4 #define ss second 5 typedef long long ll; 6 typedef pair<int, int> pii; 7 8 pii p[1010]; 9 int vis[1010]; 10 int main() { 11 int n, m; 12 scanf("%d", &n); 13 for (int i = 1; i <= n; i++) 14 scanf("%d%d", &p[i].ff, &p[i].ss); 15 scanf("%d", &m); 16 set<int> s; 17 for (int i = 1; i <= m; i++) { 18 int x; 19 scanf("%d", &x); 20 s.insert(x); 21 for (int j = 1; j <= n; j++) 22 if (p[j].ff <= x && x <= p[j].ss) 23 vis[j]++; 24 } 25 for (int i = 1; i <= n; i++) 26 if (vis[i] > 2) { 27 printf("impossible\n"); 28 return 0; 29 } 30 vector<int> ans; 31 for (int i = 1; i < n; i++) 32 if (p[i].ss == p[i + 1].ff) { 33 if (vis[i] < 2 && vis[i + 1] < 2 && s.find(p[i].ss) == s.end()) 34 ans.push_back(p[i].ss), vis[i]++, vis[i + 1]++, s.insert(p[i].ss); 35 } 36 for (int i = 1; i <= n; i++) { 37 for (int j = vis[i]; j < 2; j++) { 38 int l = p[i].ff + 1; 39 while (s.find(l) != s.end()) 40 l++; 41 s.insert(l), ans.push_back(l), vis[i]++; 42 } 43 } 44 printf("%d\n", ans.size()); 45 for (auto i : ans) 46 printf("%d ", i); 47 }
E:
solver:czq
1 /* basic header */ 2 #include <bits/stdc++.h> 3 /* define */ 4 #define ll long long 5 #define pb emplace_back 6 #define mp make_pair 7 #define eps 1e-8 8 #define lson (curpos<<1) 9 #define rson (curpos<<1|1) 10 /* namespace */ 11 using namespace std; 12 /* header end */ 13 14 int a[4], k; 15 16 int main() { 17 for (int i = 0; i < 4; i++) { 18 int x, y; scanf("%d.%d", &x, &y); 19 a[i] = x * 100 + y; 20 } 21 int x, y; scanf("%d.%d", &x, &y); k = x * 100 + y; 22 sort(a, a + 4); 23 int sum = a[1] + a[2] + a[3]; 24 if (k * 3 >= sum) return puts("infinite"), 0; 25 if (k * 3 - a[1] - a[2] < a[0]) return puts("impossible"), 0; 26 printf("%d.", (k * 3 - a[1] - a[2]) / 100); 27 int tmp = (k * 3 - a[1] - a[2]) % 100; 28 if (tmp < 10) printf("0%d\n", tmp); else printf("%d\n", tmp); 29 return 0; 30 }
F:
solver:lzh
1 #include <bits/stdc++.h> 2 using namespace std; 3 #define ff first 4 #define ss second 5 typedef long long ll; 6 typedef pair<int, int> pii; 7 8 int f[200010]; 9 int find(int x) { 10 return f[x] == x ? x : f[x] = find(f[x]); 11 } 12 bool add(int x, int y) { 13 int fx = find(x), fy = find(y); 14 if (fx != fy) { 15 f[fx] = fy; 16 return true; 17 } 18 return false; 19 } 20 int main() { 21 int n; 22 scanf("%d", &n); 23 map<int, vector<int>> m; 24 for (int i = 1; i <= n; i++) { 25 f[i] = i; 26 int j, k; 27 scanf("%d", &j); 28 while (j--) { 29 scanf("%d", &k); 30 m[k].push_back(i); 31 } 32 } 33 vector<pair<pii, int>> ans; 34 for (auto i : m) { 35 for (int j = 1; j < i.ss.size(); j++) 36 if (add(i.ss[j - 1], i.ss[j])) 37 ans.push_back({ { i.ss[j - 1], i.ss[j] }, i.ff }); 38 } 39 if (ans.size() != n - 1) 40 printf("impossible\n"); 41 else 42 for (auto i : ans) 43 printf("%d %d %d\n", i.ff.ff, i.ff.ss, i.ss); 44 }
G:
solver:zyh、czq
1 #include <iostream> 2 using namespace std; 3 long double c[501][501]; 4 long double p[501]; 5 void initC(int n) { 6 for (int i = 0; i <= n; ++i) { 7 c[i][0] = c[i][i] = 1; 8 for (int j = 1; j < i; ++j) c[i][j] = c[i - 1][j] + c[i - 1][j - 1]; 9 } 10 } 11 int main() { 12 initC(500); 13 int n, k; 14 scanf("%d%d", &n, &k); 15 for (int i = 0; i < n; ++i) scanf("%Lf", &p[i]); 16 for (int i = 0; i < n; ++i) { 17 long double ans = 0; 18 for (int j = 0; n - j >= k; ++j) { 19 ans += c[n - 1 - j][k - 1] * p[(i - j + n) % n]; 20 } 21 printf("%.12Lf ", ans / c[n][k]); 22 } 23 }
I:
solver:czq
1 /* basic header */ 2 #include <bits/stdc++.h> 3 /* define */ 4 #define ll long long 5 #define pb emplace_back 6 #define mp make_pair 7 #define eps 1e-8 8 #define lson (curpos<<1) 9 #define rson (curpos<<1|1) 10 /* namespace */ 11 using namespace std; 12 /* header end */ 13 14 const int maxn = 1e6 + 10; 15 int n, a[maxn]; 16 17 int main() { 18 scanf("%d", &n); 19 for (int i = 1; i <= n; i++) scanf("%d", &a[i]); 20 for (int i = n - 1; i >= 1; i--) { 21 if (a[i] > a[i + 1]) { 22 int r = i + 1; 23 while (r < n && a[r] == a[r + 1]) r++; 24 for (int i = 1; i <= r; i++) { 25 if (a[i] > a[r]) { 26 int l = i; 27 reverse(a + l, a + 1 + r); 28 int flag = 1; 29 for (int i = 1; i < n; i++) if (a[i] > a[i + 1]) flag = 0; 30 if (flag) return printf("%d %d\n", l, r), 0; 31 else return puts("impossible"), 0; 32 } 33 } 34 } 35 } 36 puts("1 1"); 37 return 0; 38 }