A.
Topic Link: Click to open the link
Problem Solving Ideas:
The main idea is that odd digits to lowercase letters, even digits to uppercase letters, and then lowercase corresponding to the key, uppercase corresponding door, ask a minimum of a few keys to open all doors.
Simple simulation can, initialize an English alphabet array, if encountered lowercase letters, we put the corresponding counter + +, encountered uppercase, if it corresponds to the array value is not 0, then we will--,
Otherwise buy a key.
Full code:
#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include < cmath> #include <set> #include <vector> #include <climits> #include <queue>using namespace Std;typedef Long Long ll;const int maxn = 500001;int n;string s;int vis[26];int Main () {#ifdef Doubleq freopen ("in.t XT "," R ", stdin); #endif while (CIN >> N) {memset (Vis, 0, sizeof (VIS)); Cin >> S; int len = S.length (); int cnt = 0; for (int i = 0; i < len; i + +) {if ((i+1)% 2! = 0) {Vis[s[i]-' a '] + +; } else {if (Vis[s[i]-' A ']) {vis[s[i] -' A ']--; } else {cnt + +; }}} cout << cnt << Endl; } return 0;}
B.
Topic Link: Click to open the link
Problem Solving Ideas:
Feel the IQ again suppressed ... Obviously violent O (m^2) will time out, I still have a fluke to try ... Sure enough, tle.
The positive solution is to open a sum array to record the number of reversals that occur at each location, and then to check the sum array from 0~LEN/2, set k = 0, each time K + + Sum[i], if K is odd, then swap s[i] and s[len-i-1]. This solution is correct, although not much to understand. But at least one thing is clear, that is, an interval of string reversal even several times, it is equivalent to no reversal, so just consider those reversal odd number of times.
Full code:
#include <algorithm> #include <iostream> #include <cstring> #include <complex> #include < cstdio> #include <string> #include <cmath> #include <queue>using namespace std;typedef long long LL; const int MOD = INT (1e9) +7;const int INF = 0x3f3f3f3f;const double EPS = 1e-9;const Double PI = ACOs (-1.0); m_pi;const int maxn = 200001;string s;int n;int sum[maxn];int Main () {#ifdef Doubleq freopen ("In.txt", "R", stdin); #endif while (Cin >> s) {cin >> n; int key; int len = S.length (); memset (sum, 0, sizeof (sum)); for (int i = 0; i < n; i + +) {cin >> key; SUM[KEY-1] + +; } int k = 0; for (int i = 0; i < LEN/2; i + +) {k + = Sum[i]; if (k% 2! = 0) {swap (s[i], s[len-i-1]); }} cout << s << endl; } return 0;}
C.
Topic Link: Click to open the link
Problem Solving Ideas:
The C-question feeling is simpler than the B question, the first idea of reading the question is to order, then the next comparison, then do and. The only possible problem is that the data is too big to worry long long, so open to unsigned long long.
But this problem also has a pit, that is not necessarily adjacent to the two comparisons, because according to this idea each rectangle is adjacent to four numeric values, written as I-= 2 means when two pairs of one of them is not established, the other pair is equivalent to be discarded by us, so the final result is not the largest solution, so write I--, if the conditions , we again I--。
Full code:
#include <algorithm> #include <iostream> #include <cstring> #include <complex> #include < cstdio> #include <string> #include <cmath> #include <queue>using namespace Std;typedef unsigned Long long ll;const int MOD = int (1e9) +7;const int INF = 0x3f3f3f3f;const double EPS = 1e-9;const Double PI = ACOs (-1.0); m_pi;const int maxn = 2000001;int n; LL S[maxn];bool CMP (ll A, ll b) {return a < b;} ll min (ll a, ll b) {return a < b a:b;} int main () {#ifdef Doubleq freopen ("In.txt", "R", stdin); #endif while (CIN >> N) {memset (s, 0, sizeof (s)); for (int i = 0; i < n; i + +) {cin >> s[i]; } sort (s, S + N, CMP); LL sum = 0; LL flag =-1; for (int i = n-1; I >= 0; I-) {if (S[i]-s[i-1] <= 1) {LL k = s[ I-1]; if (flag = =-1) {flag = k; } else {sum + = k * Flag; flag =-1; } I--; }//cout << sum << endl; } cout << sum << endl; } return 0;}
Codeforces Round #297 (Div. 2) (analog + string + sort)