跟之前AtCoder BC 128同一晚上的题,没有打。
这场题面很短,好评。
题目链接:https://codeforces.com/contest/1169
A:
题目又臭又长,结果是个弱智模拟。
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 int n, a, x, b, y; 21 22 int main() { 23 cin >> n >> a >> x >> b >> y; 24 while ((a != x) && (b != y)) { 25 a = a == n ? 1 : a + 1; 26 b = b == 1 ? n : b - 1; 27 if (a == b) return puts("YES"), 0; 28 } 29 puts("NO"); 30 return 0; 31 }
B:
也很弱智。
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 = 3e5 + 10; 21 int n, m, cnt[maxn]; 22 vector<pair<int, int>>v; 23 24 int check(int x) { 25 rep0(i, 0, maxn) cnt[i] = 0; 26 int s = 0; 27 rep0(i, 0, m) 28 if (v[i].first != x && v[i].second != x) { 29 cnt[v[i].first]++, cnt[v[i].second]++; 30 s++; 31 } 32 rep1(i, 1, n) 33 if (cnt[i] == s) 34 return 1; 35 return 0; 36 } 37 38 int main() { 39 scanf("%d%d", &n, &m); 40 rep1(i, 1, m) { 41 int x, y; scanf("%d%d", &x, &y); 42 v.pb(mp(x, y)); 43 } 44 if (check((*v.begin()).first) || check((*v.begin()).second)) 45 puts("YES"); 46 else puts("NO"); 47 return 0; 48 }
C:
给定n、m和n个数,每个数的范围是[0,m)。有且仅有一种操作:每次操作可以选定任意k个数,对于每个数a[i],a[i]=(a[i]+1)%m。问最少需要几次操作,使得原数列变为不下降数列。
数据范围3e5,一看就是二分题。
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 = 3e5 + 10; 21 int n, m, a[maxn]; 22 23 int main() { 24 scanf("%d%d", &n, &m); 25 rep0(i, 0, n) scanf("%d", &a[i]); 26 int l = -1, r = m; 27 while (l < r - 1) { 28 int mid = l + r >> 1, prev = 0, flag = 1; 29 rep0(i, 0, n) { 30 int lpos = a[i], rpos = a[i] + mid; 31 if ((lpos <= prev && prev <= rpos) || (lpos <= prev + m && prev + m <= rpos)) 32 continue; 33 if (a[i] > prev) prev = a[i]; 34 else { 35 flag = 0; 36 break; 37 } 38 } 39 if (flag) r = mid; else l = mid; 40 } 41 printf("%d ", r); 42 return 0; 43 }
D:
给定一个长度为n的01串s,求有多少对l、r (1≤l≤r≤n),存在至少一对x、k,满足1≤x,k≤n,l≤x<x+2k≤r,且s[x]=s[x+k]=s[x+2k]。
翻译一下就是有多少个区间,区间内至少存在一个三元组(a,b,c),a==b==c且间隔相等。
暴力,枚就完事了。
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 = 3e5 + 10; 21 int a[maxn]; 22 string s; 23 ll ans = 0; 24 25 int main() { 26 cin >> s; 27 int len = s.size(); 28 rep0(i, 0, maxn) a[i] = int_inf; 29 rep0(i, 0, len) { 30 for (int j = 1; i + 2 * j < len; j++) 31 if (s[i] == s[i + j] && s[i] == s[i + 2 * j]) { 32 a[i] = i + 2 * j; 33 break; 34 } 35 } 36 for (int i = len - 1; i >= 0; i--) a[i] = min(a[i], a[i + 1]); 37 rep0(i, 0, len) 38 if (a[i] != int_inf) ans += len - a[i]; 39 printf("%lld ", ans); 40 return 0; 41 }
E:
待补。