2018-2019 ICPC Southwestern European Regional Programming Contest (SWERC 2018)
7题,一般般。F没搞出来很可惜。
自己这场题还是充当翻译机的角色……中间发现D和H很可写,马上就把队友赶下来了(
A:
solver:lzh
1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef pair<int, int> pii; 4 typedef long long ll; 5 #define ff first 6 #define ss second 7 8 int a[1000010]; 9 int main() { 10 int n, k; scanf("%d%d", &n, &k); 11 for (int i = 1; i <= n; i++)a[i] = 1; 12 int ans = 0, cur = 0; 13 while (k--) { 14 int m, cnt = cur; scanf("%d", &m); 15 for (int i = 1; i * m <= n; i++) { 16 if (!a[i * m])cnt--; 17 else cnt++; 18 a[i * m] ^= 1; 19 } 20 ans = max(ans, cnt); 21 //cout<<cnt<<endl; 22 cur = cnt; 23 } 24 printf("%d\n", ans); 25 }
B:
solver:lzh
1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef pair<int, int> pii; 4 typedef long long ll; 5 #define ff first 6 #define ss second 7 8 int dl[20][100010], dr[20][100010]; 9 int query(int d[][100010], int l, int r, int maxx) { 10 int t = log2(r - l + 1); 11 if (maxx)return max(d[t][l], d[t][r - (1 << t) + 1]); 12 return min(d[t][l], d[t][r - (1 << t) + 1]); 13 } 14 void init(int d[][100010], int a[], int len, int maxx) { 15 for (int i = 0; i < len; i++)d[0][i] = a[i]; 16 int t = 1; 17 for (int i = 1; t <= len; i++) { 18 for (int j = 0; j + t < len; j++) 19 if (maxx)d[i][j] = max(d[i - 1][j], d[i - 1][j + t]); 20 else d[i][j] = min(d[i - 1][j], d[i - 1][j + t]); 21 t <<= 1; 22 } 23 } 24 25 int L[100010], R[100010]; 26 int main() { 27 int n; scanf("%d", &n); 28 for (int i = 0; i < n; i++)scanf("%d%d", &L[i], &R[i]); 29 init(dl, L, n, 1); 30 init(dr, R, n, 0); 31 32 int ans = 1; 33 for (int i = 1; i <= n; i++) { 34 int l = ans, r = n - i + 1; 35 while (l <= r) { 36 int mid = l + r >> 1; 37 //cout<<i<<" "<<mid<<" "<<query(dl,i-1,i+mid-2,1)<<" "<<query(dr,i-1,i+mid-2,0)<<"\n"; 38 if (query(dr, i - 1, i + mid - 2, 0) - query(dl, i - 1, i + mid - 2, 1) + 1 >= mid) { 39 ans = max(ans, mid); l = mid + 1; 40 } else r = mid - 1; 41 } 42 } 43 printf("%d\n", ans); 44 }
C:
完全没看的防AK
D:
solver:czq
1 /* basic header */ 2 #include <bits/stdc++.h> 3 /* define */ 4 #define ll long long 5 #define dou double 6 #define pb emplace_back 7 #define mp make_pair 8 #define sot(a,b) sort(a+1,a+1+b) 9 #define rep1(i,a,b) for(int i=a;i<=b;++i) 10 #define rep0(i,a,b) for(int i=a;i<b;++i) 11 #define eps 1e-8 12 #define int_inf 0x3f3f3f3f 13 #define ll_inf 0x7f7f7f7f7f7f7f7f 14 #define lson (curpos<<1) 15 #define rson (curpos<<1|1) 16 /* namespace */ 17 using namespace std; 18 /* header end */ 19 20 const int maxn = 200010, lim = 100001; 21 struct Point { 22 int x, y; 23 } p[maxn]; 24 int n, x, y, maxx[maxn], minn[maxn], monument[maxn]; 25 26 void init() { 27 for (int i = 0; i < maxn; i++) { 28 p[i].x = p[i].y = monument[i] = 0; 29 maxx[i] = -1; 30 } 31 memset(minn, 0x3f, sizeof(minn)); 32 } 33 34 int main() { 35 while (~scanf("%d%d", &x, &y)) { 36 init(); 37 scanf("%d", &n); 38 for (int i = 0; i < n; i++) { 39 scanf("%d%d", &p[i].x, &p[i].y); 40 maxx[p[i].x] = max(maxx[p[i].x], p[i].y); 41 minn[p[i].x] = min(minn[p[i].x], p[i].y); 42 } 43 int cnt = 0; 44 for (int i = 0; i < lim; i++) { 45 if (maxx[i] != -1 && minn[i] != 0x3f3f3f3f) { 46 monument[cnt++] = maxx[i]; 47 monument[cnt++] = minn[i]; 48 } 49 } 50 sort(monument, monument + cnt); 51 ll ans = x - 1, mid = monument[(cnt - 1) / 2]; 52 for (int i = 0; i < lim; i++) 53 if (maxx[i] != -1 && minn[i] != 0x3f3f3f3f) 54 ans += (ll)maxx[i] - minn[i] + abs(mid - maxx[i]) + abs(mid - minn[i]); 55 printf("%lld\n", ans); 56 } 57 return 0; 58 }
E:
solver:zyh、lzh
1 #include <iostream> 2 #include <string> 3 using namespace std; 4 char str[50001]; 5 string names[50001]; 6 int d[50001]; 7 int validate(int x) { 8 if (x > 49) return 49; 9 if (x < -50) return -50; 10 return x; 11 } 12 int main() { 13 int n; 14 int sum = 0; 15 scanf("%d", &n); 16 for (int i = 0; i < n; ++i) { 17 scanf("%s%d", str, &d[i]); 18 d[i] *= 100; 19 sum += d[i]; 20 names[i] = str; 21 } 22 int l = 10000 - sum - 49 * (n - 1); 23 int r = 10000 - sum + 50 * (n - 1); 24 if (r > 49) r = 49; 25 if (l < -50) l = -50; 26 if (l <= r) { 27 for (int i = 0; i < n; ++i) { 28 printf("%s %.2f %.2f\n", names[i].c_str(), max(0, d[i] + l) / 100.0, min(10000, d[i] + r) / 100.0); 29 } 30 } else printf("IMPOSSIBLE\n"); 31 }
F:
没搞出来
G:
很恶心的字符串题
H:
solver:czq
1 /* basic header */ 2 #include <bits/stdc++.h> 3 /* define */ 4 #define ll long long 5 #define dou double 6 #define pb emplace_back 7 #define mp make_pair 8 #define sot(a,b) sort(a+1,a+1+b) 9 #define eps 1e-8 10 #define int_inf 0x3f3f3f3f 11 #define ll_inf 0x7f7f7f7f7f7f7f7f 12 #define lson (curpos<<1) 13 #define rson (curpos<<1|1) 14 /* namespace */ 15 using namespace std; 16 /* header end */ 17 using namespace std; 18 19 const int maxn = 1e5 + 10; 20 struct Node { 21 int x, y, z, id, cnt; 22 bool operator<(const Node &rhs)const { 23 return x != rhs.x ? x < rhs.x : y != rhs.y ? y < rhs.y : z < rhs.z; 24 } 25 } info[maxn], temp[maxn]; 26 int n, m, num = 0, sum = 0, a[maxn], dis1[maxn], dis2[maxn], dis3[maxn], vis[maxn], head[maxn]; 27 vector<pair<int, int>>g[maxn]; 28 priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>>q; 29 30 int lowbit(int x) { 31 return x & -x; 32 } 33 34 void add(int pos, int val) { 35 while (pos < maxn) a[pos] += val, pos += lowbit(pos); 36 } 37 38 int query(int pos) { 39 int ret = 0; 40 while (pos) ret += a[pos], pos -= lowbit(pos); 41 return ret; 42 } 43 44 void dijkstra(int *dis, int st) { 45 for (int i = 0; i <= n; ++i) dis[i] = int_inf; 46 dis[st] = 0; 47 while (q.size()) q.pop(); 48 q.push(mp(dis[st], st)); 49 while (q.size()) { 50 pair<int, int> temp = q.top(); q.pop(); 51 if (temp.first > dis[temp.second]) continue; 52 for (int i = 0; i < (int)g[temp.second].size(); ++i) { 53 if (dis[temp.second] + g[temp.second][i].first < dis[g[temp.second][i].second]) { 54 dis[g[temp.second][i].second] = dis[temp.second] + g[temp.second][i].first; 55 q.push(mp(dis[g[temp.second][i].second], g[temp.second][i].second)); 56 } 57 } 58 } 59 } 60 61 void init() { 62 for (int i = 0; i < maxn; i++) vis[i] = 0; 63 } 64 65 void cdq(int l, int r) { 66 if (r - l <= 1) return; 67 int mid = (r + l) >> 1; 68 cdq(l, mid); cdq(mid, r); 69 int lPtr = l, rPtr = mid, cnt = 0; 70 while (lPtr < mid && rPtr < r) { 71 if (info[lPtr].y <= info[rPtr].y) { 72 add(info[lPtr].z, 1); 73 temp[cnt++] = info[lPtr++]; 74 } else { 75 int curr = query(info[rPtr].z); 76 if (curr) vis[info[rPtr].id] = info[rPtr].cnt; 77 temp[cnt++] = info[rPtr++]; 78 } 79 } 80 while (rPtr < r) { 81 int curr = query(info[rPtr].z); 82 if (curr) vis[info[rPtr].id] = info[rPtr].cnt; 83 temp[cnt++] = info[rPtr++]; 84 } 85 for (int i = l; i < lPtr; ++i) add(info[i].z, -1); 86 while (lPtr < mid) temp[cnt++] = info[lPtr++]; 87 for (int i = 0; i < cnt; ++i) info[i + l] = temp[i]; 88 } 89 90 int main() { 91 scanf("%d%d", &n, &m); sum = n, num = 0; 92 while (m--) { 93 int u, v, w; 94 scanf("%d%d%d", &u, &v, &w); 95 g[u].pb(mp(w, v)); g[v].pb(mp(w, u)); 96 } 97 // maintain distance 98 dijkstra(dis1, 0); dijkstra(dis2, 1); dijkstra(dis3, 2); 99 for (int i = 0; i < n; ++i) info[i].x = dis1[i], info[i].y = dis2[i], info[i].z = dis3[i], head[++num] = info[i].z; 100 sort(head + 1, head + 1 + num); 101 // li san hua 102 num = unique(head + 1, head + 1 + num) - head - 1; 103 for (int i = 0; i < n; ++i) info[i].z = lower_bound(head + 1, head + 1 + num, info[i].z) - head; 104 sort(info, info + n); 105 int p = 1, tot = 0; 106 // spj equal 107 for (int i = 0; i < n; ++i) { 108 if (info[i].x == info[i + 1].x && info[i].y == info[i + 1].y && info[i].z == info[i + 1].z) { 109 p++; continue; 110 } 111 info[i].cnt = p; info[tot++] = info[i]; p = 1; 112 } 113 n = tot; 114 for (int i = 0; i < n; ++i) info[i].id = i; 115 cdq(0, n); 116 for (int i = 0; i < n; ++i) sum -= vis[i]; 117 printf("%d\n", sum); 118 }
I:
solver:lzh
1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef pair<int, int> pii; 4 typedef long long ll; 5 #define ff first 6 #define ss second 7 8 char s[1010][1010]; 9 int vis[1010][1010], dd[8][2] = {-1, 0, -1, -1, -1, 1, 0, 1, 0, -1, 1, 0, 1, -1, 1, 1}; 10 11 int abc[3][15] = {{1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1}, 12 {1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1}, 13 {1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1} 14 }; 15 int add1[20], add2[20]; 16 17 int check(int x, int y, int n, int m, char cur) { 18 for (int i = x; i < x + n; i++) 19 for (int j = y; j < y + m; j++) 20 if (s[i][j] != cur || vis[i][j])return 1; 21 return 0; 22 } 23 24 int find(int stx, int sty, int x, int y, int cur) { 25 add1[0] = 0, add1[1] = x, add1[2] = x + y; 26 for (int i = 3; i < 15; i++)add1[i] = add1[i % 3]; 27 add2[0] = 0, add2[3] = x, add2[6] = x + y, add2[9] = 2 * x + y, add2[12] = 2 * x + 2 * y; 28 for (int i = 0; i < 5; i++) 29 for (int j = 1; j < 3; j++)add2[3 * i + j] = add2[3 * i + j - 1]; 30 //for(int i=0;i<15;i++)printf("%d ",add2[i]);printf("\n"); 31 32 for (int i = 0; i < 15; i++) { 33 int addn = 0, addm = 0; 34 if (i / 3 % 2 == 0)addn = x; else addn = y; 35 if (i % 3 % 2 == 0)addm = x; else addm = y; 36 37 char findchar = '.'; 38 if (abc[cur][i])findchar = '#'; 39 if (check(stx + add2[i], sty + add1[i], addn, addm, findchar)) { 40 //printf("%d\n",i); 41 //printf("%d %d %d %d\n",stx+add2[i],sty+add1[i],addn,addm); 42 return 0; 43 } 44 } 45 return 1; 46 } 47 48 int main() { 49 int ansa = 0, ansb = 0, ansc = 0; 50 int n, m; scanf("%d%d", &m, &n); 51 for (int i = 1; i <= n; i++)scanf("%s", s[i] + 1); 52 for (int i = 2; i <= n - 1; i++) 53 for (int j = 2; j <= m - 1; j++) 54 if (s[i][j] == '#') { 55 int gg = 0; 56 for (int k = 0; k < 8; k++) 57 if (s[i + dd[k][0]][j + dd[k][1]] == '#') { 58 gg++; 59 break; 60 } 61 if (!gg)s[i][j] = '.'; 62 } 63 64 for (int i = 2; i <= n - 1; i++) 65 for (int j = 2; j <= m - 2; j++) 66 if (s[i][j] == '.' && s[i][j + 1] == '#' && !vis[i][j]) { 67 int a = 1, b = 1; 68 for (int k = j + 2; k <= m - 2; k++) 69 if (s[i][k] == '#')a++; 70 else break; 71 for (int k = i + 1; k <= n - 2; k++) 72 if (s[k][j + 1] == '#')b++; 73 else break; 74 75 int x = 2 * a - b, y = 2 * b - 3 * a; 76 if (x <= 0 || y <= 0)continue; 77 78 int gg = 0; 79 for (int k = j; k <= j + a + 1; k++) 80 if (s[i - 1][k] == '#' || s[i + b][k] == '#') { 81 gg++; 82 break; 83 } 84 if (gg)continue; 85 for (int k = i; k <= i + b - 1; k++) 86 if (s[k][j] == '#' || s[k][j + a + 1] == '#') { 87 gg++; 88 break; 89 } 90 if (gg)continue; 91 92 int cur = 0; 93 if (s[i][j + x + 1] == '#' && s[i + x + y][j + x + 1] == '#' && s[i + 2 * (x + y)][j + x + 1] == '.')cur = 1; 94 if (s[i][j + x + 1] == '#' && s[i + x + y][j + x + 1] == '#' && s[i + 2 * (x + y)][j + x + 1] == '#')cur = 2; 95 if (s[i][j + x + 1] == '#' && s[i + x + y][j + x + 1] == '.' && s[i + 2 * (x + y)][j + x + 1] == '#')cur = 3; 96 97 if (!cur)continue; 98 99 //printf("%d %d %d\n",i,j,cur); 100 101 if (find(i, j + 1, x, y, cur - 1)) { 102 for (int visx = i - 1; visx <= i + b; visx++) 103 for (int visy = j; visy <= j + a + 1; visy++) 104 vis[visx][visy]++; 105 if (cur == 1)ansa++; 106 else if (cur == 2)ansb++; 107 else ansc++; 108 } 109 110 } 111 /*for(int i=1;i<=n;i++,printf("\n")) 112 for(int j=1;j<=m;j++)printf("%d",vis[i][j]);*/ 113 printf("%d %d %d\n", ansa, ansb, ansc); 114 }
J:
看都看不懂的奇怪数学题,像是乱搞
K:
solver:zyh
1 #include <bits/stdc++.h> 2 using namespace std; 3 char str[1001]; 4 int dp[1001][1001]; 5 long long strhash[1001]; 6 long long M = 1000000007; 7 long long p[1001]; 8 long long getHash(int l, int r) { 9 l++; r++; 10 return (strhash[r] - (strhash[l - 1] * p[r - l + 1]) % M + M) % M; 11 } 12 int getKey(char ch) { 13 if (ch >= 'a' && ch <= 'z') return ch - 'a' + 1; 14 if (ch >= 'A' && ch <= 'Z') return ch - 'A' + 27; 15 return ch - '0' + 54; 16 } 17 int solve(int l, int r) { 18 if (~dp[l][r]) return dp[l][r]; 19 if (l == r) { 20 dp[l][r] == 1; 21 return 1; 22 } 23 int ans = 99999999; 24 for (int i = 1; i <= r - l; ++i) { 25 int j; 26 long long rep = getHash(l, l + i - 1); 27 for (j = l; j <= r - i + 1; j += i) if (rep != getHash(j, j + i - 1)) break; 28 int f1, f2; 29 f1 = f2 = 0; 30 f1 = solve(l, l + i - 1); 31 if (j <= r) f2 = solve(j, r); 32 ans = min(ans, f1 + f2); 33 } 34 dp[l][r] = ans; 35 return ans; 36 } 37 int main() { 38 int len; 39 scanf("%d", &len); 40 scanf("%s", str); 41 p[0] = 1; 42 for (int i = 1; i <= len; ++i) p[i] = p[i - 1] * 71 % M; 43 strhash[0] = 0; 44 for (int i = 1; i <= len; ++i) strhash[i] = ((strhash[i - 1] * 71) % M + getKey(str[i - 1])) % M; 45 //cout<<getHash(0,10)<<' '<<getHash(11,21)<<endl; 46 memset(dp, -1, sizeof(dp)); 47 printf("%d\n", solve(0, len - 1)); 48 }