一直都很喜欢cf,从大一下开始, 想想现在已经差不多过了一年了吧,这一年里,真心为自己的成长感到高兴,“人弱被人欺”, 去年上次在广州地区赛时深深感受到。
B. Pasha and String
1 /***Good Luck***/ 2 #define _CRT_SECURE_NO_WARNINGS 3 #include <iostream> 4 #include <cstdio> 5 #include <cstdlib> 6 #include <cstring> 7 #include <string> 8 #include <algorithm> 9 #include <stack> 10 #include <map> 11 #include <queue> 12 #include <vector> 13 #include <set> 14 #include <functional> 15 #include <cmath> 16 #include <numeric> 17 18 #define ll long long 19 #define Zero(x) memset((x),0, sizeof(x)) 20 #define Neg(x) memset((x), -1, sizeof(x)) 21 #define dg(x) cout << #x << " = " << x 22 #define pk(x) push_back(x) 23 using namespace std; 24 int OK = 1; 25 const int maxn = 200040; 26 int arr[maxn]; 27 int tim[maxn] = { 0 }; 28 char ans[maxn]; 29 int main() { 30 //freopen("data.out", "w", stdout); 31 //freopen("data.in", "r", stdin); 32 cin.sync_with_stdio(false); 33 string s; 34 cin >> s; 35 int len = s.length(); 36 int n, a; 37 cin >> n; 38 int t; 39 for (int i = 0; i < n; ++i){ 40 cin >> arr[i]; 41 } 42 sort(arr, arr + n); 43 for (int i = 0; i < n; ++i){ 44 if (arr[i]) { 45 tim[arr[i] - 1]++; 46 tim[len - arr[i] + 1]--; 47 } 48 } 49 ll sum = 0; 50 for (int i = 0; i < len; ++i){ 51 sum += tim[i]; 52 if (sum % 2) { 53 ans[i] = s[len - i - 1]; 54 } 55 else { 56 ans[i] = s[i]; 57 } 58 } 59 cout << ans << endl; 60 }
C. Ilya and Sticks
1 /***Good Luck***/ 2 #define _CRT_SECURE_NO_WARNINGS 3 #include <iostream> 4 #include <cstdio> 5 #include <cstdlib> 6 #include <cstring> 7 #include <string> 8 #include <algorithm> 9 #include <stack> 10 #include <map> 11 #include <queue> 12 #include <vector> 13 #include <set> 14 #include <functional> 15 #include <cmath> 16 #include <numeric> 17 18 #define ll long long 19 #define Zero(x) memset((x),0, sizeof(x)) 20 #define Neg(x) memset((x), -1, sizeof(x)) 21 #define dg(x) cout << #x << " = " << x 22 #define pk(x) push_back(x) 23 using namespace std; 24 int OK = 1; 25 const int maxn = 100040; 26 int arr[maxn]; 27 28 int main() { 29 //freopen("data.out", "w", stdout); 30 //freopen("data.in", "r", stdin); 31 cin.sync_with_stdio(false); 32 int n; 33 cin >> n; 34 for(int i = 0; i < n; ++i){ 35 cin >> arr[i]; 36 } 37 sort(arr, arr + n, greater<int>() ); 38 int i = 1; 39 ll a = 0, b = 0; 40 ll sum = 0; 41 for( i = 1; i < n; ++i){ 42 if(arr[i] == arr[i - 1] || arr[i-1] - 1 == arr[i]){ 43 if(!a){ 44 a = arr[i]; 45 }else if(!b){ 46 b = arr[i]; 47 sum += a *b; 48 a = 0; b = 0; 49 } 50 ++i; 51 } 52 } 53 cout << sum << endl; 54 }
D. Arthur and Walls
1 /***Good Luck***/ 2 #define _CRT_SECURE_NO_WARNINGS 3 #include <iostream> 4 #include <cstdio> 5 #include <cstdlib> 6 #include <cstring> 7 #include <string> 8 #include <algorithm> 9 #include <stack> 10 #include <map> 11 #include <queue> 12 #include <vector> 13 #include <set> 14 #include <functional> 15 #include <cmath> 16 #include <numeric> 17 18 #define ll long long 19 #define Zero(x) memset((x),0, sizeof(x)) 20 #define Neg(x) memset((x), -1, sizeof(x)) 21 #define dg(x) cout << #x << " = " << x 22 #define pk(x) push_back(x) 23 #define pii pair<int, int> 24 using namespace std; 25 int OK = 1; 26 char ch[2001][2001]; 27 int n, m; 28 deque<pair<pii, pair<pii, pii>>> dq; 29 int a, b; 30 bool flag; 31 void check(pii t1, pii t2){ 32 int c = 0; 33 flag = false; 34 if(ch[t1.first][t1.second] == '*'){ 35 ++c; 36 a = t1.first; 37 b = t1.second; 38 } 39 if(ch[t2.first][t2.second] == '*'){ 40 ++c; 41 a = t2.first; 42 b = t2.second; 43 } 44 if(ch[t1.first][t2.second] == '*'){ 45 ++c; 46 a = t1.first; 47 b = t2.second; 48 } 49 if(ch[t2.first][t1.second] == '*'){ 50 ++c; 51 a = t2.first; 52 b = t1.second; 53 } 54 if(c == 1){ 55 flag = true; 56 } 57 } 58 void init() { 59 int i, j; 60 int c; 61 for(i = 1; i < n; ++i) 62 for(j = 1; j < m; ++j){ 63 check(make_pair(i - 1, j - 1), make_pair(i, j)); 64 if(flag) dq.push_back(make_pair(make_pair(a, b), make_pair(make_pair(i,j), make_pair(i - 1, j - 1)))); 65 } 66 } 67 68 void solve() { 69 pair<pii, pair<pii, pii>> top; 70 pii pt; 71 while(!dq.empty()){ 72 top = dq.front(); 73 dq.pop_front(); 74 pt = top.first; 75 if(ch[pt.first][pt.second] == '.') continue; 76 ch[pt.first][pt.second] = '.'; 77 if(pt.first){ 78 if(pt.second){ 79 check(make_pair(pt.first, pt.second), make_pair(pt.first - 1, pt.second - 1)); 80 if(flag){ 81 dq.push_back(make_pair(make_pair(a, b), make_pair(make_pair(pt.first, pt.second), make_pair(pt.first - 1, pt.second - 1)))); 82 } 83 84 } 85 } 86 if(pt.first < n -1 && pt.second){ 87 check(make_pair(pt.first, pt.second), make_pair(pt.first + 1, pt.second - 1)); 88 if(flag){ 89 dq.push_back(make_pair(make_pair(a, b), make_pair(make_pair(pt.first, pt.second), make_pair(pt.first + 1, pt.second - 1)))); 90 91 } 92 } 93 if(pt.first && pt.second < m - 1){ 94 check(make_pair(pt.first, pt.second), make_pair(pt.first - 1, pt.second + 1)); 95 if(flag){ 96 dq.push_back(make_pair(make_pair(a, b), make_pair(make_pair(pt.first, pt.second), make_pair(pt.first - 1, pt.second + 1)))); 97 98 } 99 } 100 if(pt.first < n - 1&& pt.second < m - 1){ 101 check(make_pair(pt.first, pt.second), make_pair(pt.first + 1, pt.second + 1)); 102 if(flag){ 103 dq.push_back(make_pair(make_pair(a, b), make_pair(make_pair(pt.first, pt.second), make_pair(pt.first + 1, pt.second + 1)))); 104 105 } 106 } 107 } 108 } 109 int main() { 110 //freopen("data.out", "w", stdout); 111 //freopen("data.in", "r", stdin); 112 cin.sync_with_stdio(false); 113 cin >> n >> m; 114 for(int i = 0; i < n; ++i) 115 cin >> ch[i]; 116 init(); 117 solve(); 118 for(int i = 0; i < n; ++i) 119 cout << ch[i] << ' '; 120 return 0; 121 }
最后说一句 “勇敢的少年啊快去创造奇迹”。