Educational Codeforces Round 53 (Rated for Div. 2) A,B,C,D,E題解
阿新 • • 發佈:2018-11-13
A. Diverse Substring
題意:找一個子串滿足任何一個字元的出現次數小於 n/2 n是子串的長度,
顯然兩個不相同的字元組成的子串就是滿足情況的;
#include<bits/stdc++.h> using namespace std; #define out fflush(stdout) #define fast ios::sync_with_stdio(0),cin.tie(0); #define FI first #define SE second typedef long long ll; typedef pair<int,int> P; const int maxn = 1000 + 7; const int INF = 0x3f3f3f3f; int n; char s[maxn]; map<char, int> mp; int main() { scanf("%d", &n); scanf("%s", s+1); for(int i = 2; i <= n; ++i) { if(s[i] != s[i-1]) { puts("YES"); printf("%c%c", s[i-1], s[i]); return 0; } } puts("NO"); return 0; }
B. Vasya and Books
題意:給定n本書的位置,從上往下,編號1~n不重複,沒找一本書需要把他上面的書全搬走,問每找一本書需要搬幾本書,如果之前已經搬出來的書不用搬動,輸出0;
思路:直接模擬
#include<bits/stdc++.h> using namespace std; #define out fflush(stdout) #define fast ios::sync_with_stdio(0),cin.tie(0); #define FI first #define SE second typedef long long ll; typedef pair<int,int> P; const int maxn = 2e5 + 7; const int INF = 0x3f3f3f3f; int n; int a[maxn], b[maxn]; int main() { scanf("%d", &n); for(int i = 1; i <= n; ++i) { scanf("%d", &a[i]); } for(int i = 1; i <= n; ++i) { scanf("%d", &b[i]); } int id = 1; set<int> st; for(int i = 1; i <= n; ++i) { if(st.count(b[i])) { printf("%d%c", 0, (i == n ? '\n' : ' ')); } else { int ans = 1; while(a[id] != b[i]) { st.insert(a[id]); id++, ans++; } id++; printf("%d%c", ans, (i == n ? '\n' : ' ')); } } return 0; }
C. Vasya and Robot
題解:https://blog.csdn.net/xiang_6/article/details/83686299
D. Berland Fair
題解:https://blog.csdn.net/xiang_6/article/details/83686379
E. Segment Sum
題解: