Codeforces Round #806 (Div. 4)
作者:互联网
A. YES or YES?
思路:algorithm库里有一个transform函数可以将字符串转为大写,然后判断是否等于YES
#include <bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int, int> PII; const int N = 100010; int n, m; int a[N]; void solve() { cin >> n; while (n--) { string s; cin >> s; transform(s.begin(), s.end(), s.begin(), ::toupper); if (s != "YES") cout << "NO" << endl; else cout << "YES" << endl; } } int main() { int T = 1; //cin >> T; while (T--) { solve(); } return 0; }
B. ICPC Balloons
思路:当一个字母首次出现的时候加2,不是首次出现就加1
#include <bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int, int> PII; const int N = 100010; int n, m; int a[N]; void solve() { cin >> n; set<char> s; int res = 0; for (int i = 1; i <= n; i ++ ) { char ch; cin >> ch; if(s.count(ch)) res += 1; else res += 2; s.insert(ch); } cout << res << endl; } int main() { int T = 1; cin >> T; while(T -- ) { solve(); } return 0; }
C. Cypher
思路:反向操作,给出的字符串U就往下转,即减1,D就往上转,即加1注意0往下转和9往上转的情况
#include <bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int, int> PII; const int N = 100010; int n, m; int a[N]; void solve() { cin >> n; int res[110]; for (int i = 1; i <= n; i ++ ) { cin >> res[i]; } for (int i = 1; i <= n; i ++ ) { int cnt; cin >> cnt; while(cnt -- ) { char op; cin >> op; if(op == 'U') { if(res[i] == 0) res[i] = 9; else res[i]--; } else { if(res[i] == 9) res[i] = 0; else res[i]++; } } cout << res[i] << ' '; } cout << endl; } int main() { int T = 1; cin >> T; while(T -- ) { solve(); } return 0; }
D. Double Strings
思路:暴力,因为每个字符串最多就8位,从第一个字母开始从前向后分成两部分,找前后两部分有没有
#include <bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int, int> PII; const int N = 100010; int n, m; int a[N]; void solve() { cin >> n; set<string> s; vector<string> v; string res = ""; for (int c = 1; c <= n; c ++ ) { string str; cin >> str; s.insert(str); v.push_back(str); } for (int i = 0; i < v.size(); i ++ ) { bool flag = false; string tmp = ""; for (int j = 0; j < v[i].size(); j ++ ) { tmp += v[i][j]; if(tmp == v[i]) continue; if(s.count(tmp)) { string tmp2 = ""; for (int k = j + 1; k < v[i].size(); k ++ ) tmp2 += v[i][k]; if(s.count(tmp2)) { res += "1"; flag = true; break; } } } if(!flag) res += "0"; } cout << res << endl; } int main() { int T = 1; cin >> T; while (T--) { solve(); } return 0; }
F. Yet Another Problem About Pairs Satisfying an Inequality
思路:分成三个不等式来看,ai<i, aj<j, i<aj, 然后可以先把ai<i的数存起来,然后就只需要找满足i<aj的数就可以了,这里可以用lower_bound,找某一个存起来的数前面有多少个数的坐标比它的值小
#include <bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int, int> PII; const int N = 200010; int n, m; struct node{ LL val, idx; bool less; bool operator< (const node& t) const{ return idx < t.idx; } } a[N]; int sum[N]; void solve() { cin >> n; set<node> s; vector<LL> v; for (int i = 1; i <= n; i ++ ) { cin >> a[i].val; a[i].idx = i; if(a[i].val - a[i].idx >= 0) a[i].less = false; else a[i].less = true; if(a[i].less) { s.insert(a[i]); v.push_back(a[i].idx); } } sort(v.begin(), v.end()); // for (int i = 0; i < v.size(); i ++ ) // cout << v[i].val << ' ' << v[i].idx << endl; LL res = 0; for(auto x: s) { //v[j].val -> v[i].idx LL tmp = lower_bound(v.begin(), v.end(), x.val) - v.begin(); res += tmp; } cout << res << endl; } int main() { int T = 1; cin >> T; while (T--) { solve(); } return 0; }
标签:typedef,int,res,Codeforces,long,--,solve,Div,806 来源: https://www.cnblogs.com/yctql/p/16475734.html