Topic links: https://codeforces.com/contest/1216
A:
The meaning of problems: only a given a, b of the strings, the executable operations into a b, b into a, Q a minimum number of operations, such that any of the first even-number in a, b are equal.
idea: iterate again just fine, it does not meet the conditions change.
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 5 using namespace std; 6 7 int n, ans; 8 string a; 9 10 int main() 11 { 12 cin >> n >> a; 13 int len = n; 14 if (n % 2 != 0) len -= 1; 15 16 for (int i = 0; i < len; i ++ ) 17 { 18 if (a[i] == 'a') 19 { 20 if (a[i + 1] == 'b') i ++ ; 21 else 22 { 23 a[i + 1] = 'b'; 24 ans ++ ; 25 i ++ ; 26 } 27 } 28 else 29 { 30 if (a[i + 1] == 'a') i ++ ; 31 else 32 { 33 a[i + 1] = 'a'; 34 ans ++ ; 35 i ++ ; 36 } 37 } 38 } 39 40 cout << ans << endl; 41 cout << a; 42 return 0; 43 44 }
B:
Meaning of the questions: shooting n targets, each have different consumption, and asked in what order the shooting may consume the least.
idea: greedy, sorted, in order from largest to start shooting.
1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 5 using namespace std; 6 const int MAXN = 1000 + 10; 7 int n, ans, a[MAXN], b[MAXN]; 8 9 bool cmp(int x, int y) 10 { 11 return x > y; 12 } 13 14 int main() 15 { 16 cin >> n; 17 for (int i = 0; i < n; i ++ ) 18 { 19 cin >> a[i]; 20 b[i] = a[i]; 21 } 22 23 sort(a, a + n, cmp); 24 25 for (int i = 0; i < n; i ++ ) 26 { 27 ans += a[i] * i + 1; 28 } 29 30 cout << ans << endl; 31 for (int i = 0; i < n; i ++ ) 32 { 33 for (int j = 0; j < n; j ++ ) 34 { 35 if (a[i] == b[j]) 36 { 37 cout << j + 1 << " "; 38 b[j] = -1; 39 } 40 } 41 } 42 return 0; 43 }
D:
The meaning of problems: n kinds sword, m each have the sword to the k individuals, each s sword stolen, stolen and each is the same type of sword, in order to know the remaining sword stolen the number of a 1 , a 2 .. a the n-, ask at least steal the sword of man is.
idea: Take the remaining number of the largest number and the other A n- subtraction, the calculated greatest common divisor is the number of each of the sword stolen subtracting these numbers, the difference is that in addition to the number of accumulated gcd
1 include <iostream> 2 #include <cstdio> 3 #include <bits/stdc++.h> 4 5 using namespace std; 6 typedef long long ll; 7 const int MAXN = 2e5 + 10; 8 ll n, a[MAXN], b[MAXN], ss; 9 10 int main() 11 { 12 scanf("%lld",&n); 13 for (int i = 0; i < n; i ++ ) 14 { 15 scanf("%lld",&a[i]); 16 ss = max(a[i], ss); 17 } 18 for (int i = 0; i < n; i ++ ) b[i] = ss - a[i]; 19 20 ll c = 0; 21 for (int i = 0; i < n; i ++ ) 22 { 23 c = __gcd(c,b[i]); 24 } 25 ll ans = 0; 26 for (int i = 0; i < n; i ++ ) 27 { 28 ans += b[i] / c; 29 } 30 cout << ans << " " << c; 31 return 0; 32 }