PetroChina Personal Training Competition 18
G - Remove a Progression
solution
Regular topic, give you a sequence of length n n n, from 1...n1...n1...n
An algorithm, i_thi-thi_th, takes the number of iii from the sequence.
When asked what number of xxx is undesirable, the legitimacy of xxx is guaranteed.
Write a few more nnn s and find that the sequence only has even numbers. Output 2 x 2 * x 2 x is enough.
#include<cstdio> #include<string> #include<iostream> #include<map> #include<algorithm> #include<set> using namespace std; typedef unsigned long long ull; const int MAXN = 1e5 + 10; int main() { int t; cin >> t; while (t--) { int n, x; cin >> n >> x; cout << 2 * x << endl; } return 0; }
H - Yet Another Crosses Problem
solution
Give you a graph where the points on the graph are either' x 27;\ x 27; x 27;',' x 27;', or'.'& x 27;', & x 27;', when' x 27;\ x 27;\ x 27;\ x 27 \ is a whole row and a whole column, you think there is a cross in the graph.
Give you a picture and ask at least a few dots to have a cross.
Greedy to find.
The preprocessing saves the number of'.'& x27;. & x27;','.''of the next row and column, and then traverses it.
Note that if the intersection of a row and a column is'.'& x27;. & x27;'.', you need to answer 1-1_ 1.
#include<cstdio> #include<string> #include<iostream> #include<map> #include<string.h> #include<algorithm> #include<set> using namespace std; typedef unsigned long long ull; const int MAXN = 5e4 + 10; int a[MAXN], b[MAXN]; string s[MAXN]; int main() { int t; cin >> t; while (t--) { int n, m; cin >> n >> m; memset(a, 0, sizeof(a)); memset(b, 0, sizeof(b)); for (int i = 0; i < n; i++) { cin >> s[i]; for (int j = 0; j < m; j++) if (s[i][j] == '.') a[i]++, b[j]++; } int minn=4*5e5; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) if (s[i][j] == '.') minn = min(minn, a[i] + b[j] - 1); else minn = min(minn, a[i] + b[j]); cout <<minn<<endl; } return 0; }
I - From S To T
General idea of the title
Give you three strings s,t,ps,t,ps,t,p.
Operate optoptopt to place any long substring in ppp in any position of sss.
Ask if you can turn sss into ttt through optoptopt.
solution
First look at sss, can it be changed into ttt. That is, as long as SSS has, TTT has, and the order is the same.
See if the letters in ttt can complement sss.
#include<cstdio> #include<string.h> #include<iostream> #include<map> #include<algorithm> #include<set> using namespace std; typedef unsigned long long ull; const int MAXN = 1e2 + 10; char s[MAXN], t[MAXN], p[MAXN]; int main() { int n; cin >> n; while (n--) { cin >> s >> t >> p; int len1 = strlen(s), len2 = strlen(t), len3 = strlen(p); int j = 0; for (int i = 0; i < len2&&j<len1; i++) if (s[j] == t[i]) j++; if (j != len1) { cout << "NO" << endl; continue; } map<char, int>mp; for (int i = 0; i < len1; i++) mp[s[i]] ++; for (int i = 0; i < len3; i++) mp[p[i]] ++; bool f = 1; for (int i = 0; i < len2; i++) if (mp[t[i]]) mp[t[i]]--; else{ cout << "NO" << endl; f = 0; break; } if (f) cout << "YES" << endl; } return 0; }