A.Piling Up
# include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int r;
cin >> r;
if(1 <= r && r <= 99) cout << 100 - r << endl;
else if(100 <= r && r <= 199) cout << 200 - r << endl;
else if(200 <= r <= 299) cout << 300 - r << endl;
return 0;
}
B.Japanese Cursed Doll
# include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n, t, p;
cin >> n >> t >> p;
int peaple[n];
for(int i = 0;i < n;i ++){
cin >> peaple[i];
}
sort(peaple, peaple + n);
if(peaple[n - p] >= t) {
cout << "0" << endl;
}
else if(peaple[n - p] < t) {
cout << t - peaple[n - p] << endl;
}
return 0;
}
C.Avoid K Palindrome 2
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n, k;
cin >> n >> k;
string s;
cin >> s;
sort(s.begin(), s.end());
int ans = 0;
do {
int flag = 0;
for(int i = 0;i < n - k + 1;i ++){
if(s[i] == s[i + k - 1]){
string tmp = s.substr(i, k);
// cout << tmp << endl;
string com = tmp;
reverse(tmp.begin(), tmp.end());
if(tmp == com){
flag = 1;
}
}
}
if(flag == 0) {
// cout << s << endl;
ans += 1;
}
} while (next_permutation(s.begin(), s.end()));
cout << ans <<endl;
return 0;
}
D.Palindromic Number
n = int(input())
tmp = list(str(n))
l = len(tmp)
if n <= 10:
res = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
print(res[n - 1])
exit(0)
if tmp[0] == '1' and tmp[1] != '0': # 为偶数
res = []
res.extend(tmp[1:l] + tmp[1:l][::-1])
else:
if tmp[0] == '1' and tmp[1] == '0':
res = ['9']
res.extend(tmp[2:l])
res.extend(tmp[2:l - 1][::-1])
res.extend(['9'])
else:
res = [str(int(tmp[0]) - 1)]
res.extend(tmp[1:l])
res.extend(tmp[1:l - 1][::-1])
res.extend(str(int(tmp[0]) - 1))
sum = 0
for i in res:
print(i, end="")
E.Sinking Land
#include <bits/stdc++.h>
using namespace std;
const int H = 1010, W = 1010, Y = 100010;
bool check[H][W];
int board[H][W];
queue<int> q[Y];
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int h, w, y;
cin >> h >> w >> y;
int ans = h * w;
for(int i = 0;i < h;i ++){
for(int j = 0;j < w;j ++){
cin >> board[i][j];
if(i == 0 || i == h - 1 || j == 0 || j == w - 1){
q[board[i][j]].push(i * w +j);
check[i][j] = true;
}
}
}
int dx[4] = {0, 0, -1, 1}, dy[4] = {-1, 1, 0, 0};
for(int i = 1;i <= y;i ++){
while(!q[i].empty()){
ans --;
int t = q[i].front();
int x = t / w, y = t % w; // 解码
q[i].pop();
for(int j = 0;j < 4;j ++){
int nx = x + dx[j], ny = y + dy[j];
if(0 <= nx && nx < h && 0<= ny && ny < w){
if(check[nx][ny] == false){
q[max(board[nx][ny], i)].push(nx * w + ny);
check[nx][ny] = true;
}
}
}
}
cout << ans << endl;
}
return 0;
}