Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final)
生活随笔
收集整理的這篇文章主要介紹了
Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
A. Doggo Recoloring
ps:注意 n == 1
B. Weakened Common Divisor
題解:WCD出現中的數必然是 < a, b >中某個數的公約數。而 < a, b > 的貢獻和 a * b 的貢獻是等價,所以gcd就好了。
const int N = 150005;struct node {LL sum, x, y; }a[N];LL gcd(LL x, LL y) {return (!y ? x : gcd(y, x % y)); }void ca(LL x) {for (int i = 2; i <= (int)sqrt(x); ++i) if (x % i == 0) {cout << i << endl;return ;}cout << x << endl; }LL n;int main() {sc(n);for (int i = 1; i <= n; ++i) {sc(a[i].x), sc(a[i].y);a[i].sum = a[i].x * a[i].y;}if (n == 1) {cout << a[1].x << endl;return 0;}LL res = gcd(a[1].x, a[2].sum);for (int i = 3; i <= n; ++i) {res = gcd(res, a[i].sum);}if (res != 1) {ca(res);return 0;}res = gcd(a[1].y, a[2].sum);for (int i = 3; i <= n; ++i) {res = gcd(res, a[i].sum);}if (res != 1){ca(res);return 0;}cout << "-1" << endl;return 0;}
?C. Plasticine zebra
題解:觀察可得,分成幾部分考慮,中間的最大值,以及頭和尾的拼接。(細節啊啊啊啊啊,沒想清楚魯代碼是很危險的!!!!),頭部如果是奇數,那么尾部和頭部是相反的。
const int N = 150005;string s;int main() {cin >> s;int n = s.size();if (n == 1) {cout << 1 << endl;return 0;}int res = 1, ans = 0;char last = s[0];for (int i = 1; i < n; ++i) {if (last != s[i]) res++;else {upd(ans, res);res = 1;}last = s[i];}if (res) upd(ans, res);last = s[0];int l = 1, r = 1;for (int i = 1; i < n; ++i) {if (last != s[i]) l++;else break;last = s[i];}if (l & 1) {if (last == 'b') last = 'w';else last = 'b';}if (s[n - 1] != last) r = 0;else {for (int i = n - 2; ~i; --i) {if (last != s[i]) r++;else break;last = s[i];}}if ((l != 1 || r != 1) && l + r <= n) {upd(ans, l + r);}cout << ans << endl;return 0; }?
轉載于:https://www.cnblogs.com/zgglj-com/p/9504505.html
總結
以上是生活随笔為你收集整理的Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: docker进阶篇(一) ---- Vo
- 下一篇: OI暑假集训游记