文章目录
AtCoder Beginner Contest 043
A - Children and Candies (ABC Edit)
题意:
题解:
代码:
#include <bits/stdc++.h>
#define int long long
#define debug(x) cout << #x << " = " << x << endl;
using namespace std;
inline int read() {
int s = 0, w = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {if (ch == '-') w = -1; ch = getchar();}
while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
return s * w;
}
int const MAXN = 2e5 + 10;
int n, m, T;
signed main() {
cin >> n;
cout << (1 + n) * n / 2;
return 0;
}
B - Unhappy Hacking (ABC Edit)
题意:
题解:
代码:
#include <bits/stdc++.h>
#define int long long
#define debug(x) cout << #x << " = " << x << endl;
using namespace std;
inline int read() {
int s = 0, w = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {if (ch == '-') w = -1; ch = getchar();}
while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
return s * w;
}
int const MAXN = 2e5 + 10;
int n, m, T;
signed main() {
string s;
cin >> s;
stack<char> stk;
for (int i = 0; i <s.size(); ++i ) {
if (s[i] != 'B') stk.push(s[i]);
else if (stk.size()) stk.pop();
}
string res = "";
while(stk.size()) {
res += stk.top();
stk.pop();
}
reverse(res.begin(), res.end());
cout << res;
return 0;
}
C - Be Together
题意:
题解:
代码:
#include <bits/stdc++.h>
#define int long long
#define debug(x) cout << #x << " = " << x << endl;
using namespace std;
inline int read() {
int s = 0, w = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {if (ch == '-') w = -1; ch = getchar();}
while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
return s * w;
}
int const MAXN = 2e5 + 10;
int n, m, T;
int a[MAXN];
signed main() {
cin >> n;
int Min = 1e18, Max = -1e18;
for (int i = 1; i <= n; ++i) cin >> a[i], Min = min(Min, a[i]), Max = max(Max, a[i]);
int tmp_Min = 1e18;
for (int i = Min; i <= Max; ++i) {
int tmp = 0;
for (int j = 1; j <= n; ++j) {
tmp += (a[j] - i) * (a[j] - i);
}
tmp_Min = min(tmp_Min, tmp);
}
cout << tmp_Min;
return 0;
}
D - Unbalanced
题意:
题解:
代码:
#include <bits/stdc++.h>
#define int long long
#define debug(x) cout << #x << " = " << x << endl;
using namespace std;
inline int read() {
int s = 0, w = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {if (ch == '-') w = -1; ch = getchar();}
while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
return s * w;
}
int const MAXN = 2e5 + 10;
int n, m, T;
signed main() {
int s = -1, e = -1;
int flg = 0;
string ss;
cin >> ss;
for (int i = 0; i < ss.size(); ++i) {
if (ss[i] == ss[i + 1]) {
s = i, e = i + 1;
flg = 1;
break;
}
else if (ss[i] == ss[i + 2]) {
s = i, e = i + 2;
flg = 1;
break;
}
}
if (flg) cout << s + 1 << " " << e + 1 << endl;
else cout << -1 << " " << -1 ;
return 0;
}