比赛链接:https://codeforces.ml/contest/1602
A. Two Subsequences 直接找到最小的字符输出,然后把剩下的也输出
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 #include <bits/stdc++.h> using namespace std;typedef long long ll;typedef pair<int , int > pii;typedef unsigned long long ull;const ll inf = 1e18 ;const int N = 1e5 + 10 ;const int M = 1e6 + 10 ;const double eps = 1e-8 ;const int mod = 1e9 + 7 ;#define fi first #define se second #define re register #define lowbit (-x&x) void solve () { int T; cin >> T; while (T--) { string s; cin >> s; vector<int > vis (100 +1 ) ; int idx = 0 ; for (int i = 1 ; i < s.size (); i++) { if (s[i]< s[idx]) { idx = i; } } vis[idx] = 1 ; cout << s[idx] << ' ' ; for (int i = 0 ; i < s.size (); i++) { if (!vis[i]) cout << s[i]; } cout << endl; } } signed main () { ios_base::sync_with_stdio (false ); cin.tie (0 ); cout.tie (0 ); #ifdef ACM_LOCAL freopen ("input" , "r" , stdin); freopen ("output" , "w" , stdout); #endif #ifdef ACM_LOCAL auto start = clock (); #endif int t = 1 ; while (t--) solve (); #ifdef ACM_LOCAL auto end = clock (); cerr << "Run Time: " << double (end - start) / CLOCKS_PER_SEC << "s" << endl; #endif return 0 ; }
B. Divine Array 可以看出超过n次操作肯定会趋于不变,因此$n^2$暴力一下
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 #include <bits/stdc++.h> using namespace std;typedef long long ll;typedef pair<int , int > pii;typedef unsigned long long ull;const ll inf = 1e18 ;const int N = 1e5 + 10 ;const int M = 1e6 + 10 ;const double eps = 1e-8 ;const int mod = 1e9 + 7 ;#define fi first #define se second #define re register #define lowbit (-x&x) int a[N];int b[2005 ][2005 ];void solve () { int T; cin >> T; while (T--) { int n; cin >> n; for (int i = 1 ; i <= n; i++) { for (int j = 1 ; j <= n; j++) { b[i][j] = 0 ; } } for (int i = 1 ; i <= n; i++) cin >> a[i], b[0 ][i] = a[i]; for (int i = 1 ; i <= n; i++) { vector<int > cnt (n+1 ) ; for (int j = 1 ; j <= n; j++) { cnt[b[i-1 ][j]]++; } for (int j = 1 ; j <= n; j++) { b[i][j] = cnt[b[i-1 ][j]]; } } int q; cin >> q; while (q--) { int x, k; cin >> x >> k; if (k > n) cout << b[n][x] << endl; else cout << b[k][x] << endl; } } } signed main () { ios_base::sync_with_stdio (false ); cin.tie (0 ); cout.tie (0 ); #ifdef ACM_LOCAL freopen ("input" , "r" , stdin); freopen ("output" , "w" , stdout); #endif #ifdef ACM_LOCAL auto start = clock (); #endif int t = 1 ; while (t--) solve (); #ifdef ACM_LOCAL auto end = clock (); cerr << "Run Time: " << double (end - start) / CLOCKS_PER_SEC << "s" << endl; #endif return 0 ; }
C. Array Elimination 从进制角度考虑,每次取k个&肯定会消除k个1,因此每位上的和都是k的倍数,那么可以实现。
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 #include <bits/stdc++.h> using namespace std;typedef long long ll;typedef pair<int , int > pii;typedef unsigned long long ull;const ll inf = 1e18 ;const int N = 2e5 + 10 ;const int M = 1e6 + 10 ;const double eps = 1e-8 ;const int mod = 1e9 + 7 ;#define fi first #define se second #define re register #define lowbit (-x&x) int a[N];int sum[31 ];void solve () { int T; cin >> T; while (T--) { int n; cin >> n; for (int i = 1 ; i <= n; i++) cin >> a[i]; for (int i = 0 ; i < 30 ; i++) sum[i] = 0 ; for (int i = 1 ; i <= n; i++) { for (int j = 0 ; j < 30 ; j++) { sum[j] += (a[i] >> j & 1 ); } } for (int i = 1 ; i <= n; i++) { int ff = 0 ; for (int j = 0 ; j < 30 ; j++) { if (sum[j] % i != 0 ) { ff = 1 ; } } if (!ff) cout << i << ' ' ; } cout << endl; } } signed main () { ios_base::sync_with_stdio (false ); cin.tie (0 ); cout.tie (0 ); #ifdef ACM_LOCAL freopen ("input" , "r" , stdin); freopen ("output" , "w" , stdout); #endif #ifdef ACM_LOCAL auto start = clock (); #endif int t = 1 ; while (t--) solve (); #ifdef ACM_LOCAL auto end = clock (); cerr << "Run Time: " << double (end - start) / CLOCKS_PER_SEC << "s" << endl; #endif return 0 ; }
D. Frog Traveler 有点毒瘤的题,开始还以为是线段树优化建图,然后跑最短路。赛中忽略了一个重要的条件就是不能往回跳,利用这个条件剪枝就可以了。
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 #include <bits/stdc++.h> using namespace std;typedef long long ll;typedef pair<int , int > pii;typedef unsigned long long ull;const ll inf = 1e18 ;const int N = 3e5 + 10 ;const int M = 1e6 + 10 ;const double eps = 1e-8 ;const int mod = 1e9 + 7 ;#define fi first #define se second #define re register #define lowbit (-x&x) #define endl '\n' int a[N], b[N], dis[N], n, pre[N];void print (int x) { if (x == n) return ; print (pre[x]); cout << x << ' ' ; } void solve () { cin >> n; for (int i = 1 ; i <= n; i++) cin >> a[i]; for (int i = 1 ; i <= n; i++) cin >> b[i]; memset (dis, 0x3f , sizeof dis); queue<int > q; q.push (n); int dep = n; dis[n] = 0 ; while (q.size ()) { int now = q.front (); q.pop (); if (now <= 0 ) { cout << dis[now] << endl; print (now); return ; } int x = now + b[now]; for (int v = min (dep-1 , x-1 ); v >= x-a[x]; v--) { if (dis[v] > dis[now] + 1 ) { dis[v] = dis[now] + 1 ; pre[v] = now; q.push (v); } } dep = min (dep, x - a[x]); } cout << -1 << endl; } signed main () { ios_base::sync_with_stdio (false ); cin.tie (0 ); cout.tie (0 ); #ifdef ACM_LOCAL freopen ("input" , "r" , stdin); freopen ("output" , "w" , stdout); #endif #ifdef ACM_LOCAL auto start = clock (); #endif int t = 1 ; while (t--) solve (); #ifdef ACM_LOCAL auto end = clock (); cerr << "Run Time: " << double (end - start) / CLOCKS_PER_SEC << "s" << endl; #endif return 0 ; }