Codeforces round #258 (Div. 2) [ABCD]
ACM
Address: codeforces round #258 (Div. 2)
A-game with sticks
Question:
Akshat and malvika two people play a game, horizontal and vertical n, m wooden bars are arranged in the # type, each time a point is taken away, the intersection of the two sticks to be removed, Akshat first hand, give n, M asked who wins.
Analysis:
Obviously, no matter which point is taken away, the rest is (N-1 m-1), and the final state is (0, x) or (x, 0 ), that is, take Min (n, m)-1 times to judge the parity.
Code:
/** Author: illuz <iilluzen[at]gmail.com>* File: A.cpp* Create Date: 2014-07-24 23:32:17* Descripton: */#include <cstdio>#include <algorithm>using namespace std;const int N = 0;int a, b;int main() {scanf("%d%d", &a, &b);if (min(a, b) % 2) {puts("Akshat");} else {puts("Malvika");}return 0;}
B-sort the Array
Question:
For a sequence, determine whether to increase the whole sequence by turning the number of intermediate segments and give the flip interval.
Analysis:
The number is 10 ^ 5, so you can sort them directly and find out the interval to verify.
Code:
/** Author: illuz <iilluzen[at]gmail.com>* File: B.cpp* Create Date: 2014-07-24 23:49:35* Descripton: */#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int N = 1e5 + 10;int n, beg, end, flag;int a[N], b[N];bool cont;int main() {scanf("%d", &n);for (int i = 0; i < n; i++) {scanf("%d", &a[i]);b[i] = a[i];}sort(b, b + n);beg = 0;end = n - 1;while (beg < n && a[beg] == b[beg])beg++;while (end >= 0 && a[end] == b[end])end--;if (beg == n) {printf("yes\n");printf("1 1\n");return 0;}flag = true;for (int i = 0; i <= end - beg; i++) {//cout << b[beg + i] << ' ' << a[end - i] << endl;if (b[beg + i] != a[end - i]) {flag = false;break;}}if (flag) {printf("yes\n");printf("%d %d\n", beg + 1, end + 1);} else {printf("no\n");}return 0;}
C-predict outcome of the game
Question:
The three teams are going to have n football matches, and K matches are already in progress. It is known that the two teams have different victories: d1, and the two teams have different victories: D2, it is not possible that the three teams won the same game, that is, the draw.
Analysis:
We only know the difference between D1 and D2, but we do not know that there are many such differences. Therefore, we can determine four situations:
- Determine the legality of the number of matches: Determine whether the number of matches has exceeded K. If not, determine whether (k-S) can be divisible by 3.
- Determine the number of remaining games: Determine whether the number of remaining games can be filled out by the three teams. If yes, check whether the number of remaining games after the deduction can be divided by three.
Code:
/** Author: illuz <iilluzen[at]gmail.com>* File: C.cpp* Create Date: 2014-07-25 00:34:20* Descripton: */#include <iostream>using namespace std;typedef long long ll;ll t, k, n, d1, d2, md;bool jg(ll a, ll b, ll c) {ll s = a + b + c;if (k < s || (k - s) % 3)return 0;ll t = n - k - (3 * max(max(a, b), c) - s);if (t < 0 || t % 3)return 0;return 1;}int main() {cin >> t;while (t--) {cin >> n >> k >> d1 >> d2;md = max(d1, d2);if (jg(0, d1, d1 + d2) ||jg(d1 + d2, d2, 0) ||jg(d1, 0, d2) ||jg(md - d1, md, md - d2))cout << "yes" << endl;elsecout << "no" << endl;}return 0;}
D-count good substrings
Question:
A string composed of A and B. If it is compressed, it becomes a good string. A string contains several good strings with an even number and an odd number.
Analysis:
We can find that the compressed string is...ababab...
This format, so the first and last characters are the same, that is, the good string.
We also need to prove that the first and last strings of any good string are the same, which is not difficult.
In case of parity, it can be found that the string composed of a and the characters in the middle of any two odd positions is of an odd length, which is the same as the even position and B. The string of A at the odd and even positions is of an even length.
Code:
/** Author: illuz <iilluzen[at]gmail.com>* File: D.cpp* Create Date: 2014-07-25 10:49:46* Descripton: */#include <iostream>#include <string>#define f(a) (a*(a-1)/2)using namespace std;string s;long long r[2][2];int main() {cin >> s;for (int i = 0; s[i]; i++)r[i&1][s[i]-'a']++;cout << r[0][0] * r[1][0] + r[0][1] * r[1][1] << ' ' << f(r[0][0]) + f(r[0][1]) + f(r[1][0]) + f(r[1][1]) + s.length() << endl;return 0;}
Conclusion: The accesskey of orz sail God. Question e involves the reverse yuan ~