# Codeforces Round #662 (Div. 2)

## A. Rainbow Dash, Fluttershy and Chess Coloring (CF 1393 A)

### 解题思路

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

int main(void) {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int kase; cin>>kase;
for (int ii = 1; ii <= kase; ii++) {
int n;
cin>>n;
cout<<(n/2+1)<<endl;
}
return 0;
}


## B. Applejack and Storages (CF 1393 B)

### 解题思路

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

template <typename T>
int s = 0, c = getchar();
x = 0;
while (isspace(c)) c = getchar();
if (c == 45) s = 1, c = getchar();
while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
if (s) x = -x;
}

template <typename T>
void write(T x, char c = ' ') {
int b[40], l = 0;
if (x < 0) putchar(45), x = -x;
while (x > 0) b[l++] = x % 10, x /= 10;
if (!l) putchar(48);
while (l) putchar(b[--l] | 48);
putchar(c);
}

const int N = 1e5+8;

int n,q,l;

int cnt[N];

multiset<int> two,four;

char s[5];

int main(void) {
for(int u,i = 1; i <= n; ++ i){
if (cnt[u] % 4 == 3){
four.insert(u);
}
if (cnt[u] % 2 == 1){
two.insert(u);
}
cnt[u]++;
}
while(q--){
scanf("%s",s);
if (s[0] == '+'){
if (cnt[l] % 4 == 3){
four.insert(l);
}
if (cnt[l] % 2 == 1){
two.insert(l);
}
cnt[l]++;
}else{
if (cnt[l] % 4 == 0){
four.erase(four.find(l));
}
if (cnt[l] % 2 == 0){
two.erase(two.find(l));
}
cnt[l]--;
}
if (four.size() >= 2) puts("YES");
else if (four.size() == 0) puts("NO");
else if (two.size() >=4) puts("YES");
else puts("NO");
}
return 0;
}


## C. Pinkie Pie Eats Patty-cakes (CF 1393 C)

### 解题思路

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
template <typename T>
int s = 0, c = getchar();
x = 0;
while (isspace(c)) c = getchar();
if (c == 45) s = 1, c = getchar();
while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
if (s) x = -x;
}

template <typename T>
void write(T x, char c = ' ') {
int b[40], l = 0;
if (x < 0) putchar(45), x = -x;
while (x > 0) b[l++] = x % 10, x /= 10;
if (!l) putchar(48);
while (l) putchar(b[--l] | 48);
putchar(c);
}

int main(void) {
for (int ii = 1; ii <= kase; ii++) {
int n;
vector<int> tot(n+1);
int ma = 0;
int cnt = 0;
for(int a, i = 1; i <= n; ++ i){
tot[a]++;
if (ma < tot[a]){
ma = tot[a];
cnt = 1;
}else if (ma == tot[a])
++cnt;
}
int ans = (n - ma * cnt) / (ma - 1) + cnt - 1;
write(ans,'\n');
}
return 0;
}


## D. Rarity and New Dress (CF 1393 D)

### 解题思路

$up[i][j] = \min(up[i-1][j], \min(l[i][j], r[i][j])$

$down[i][j] = \min(down[i+1][j], \min(l[i][j], r[i][j])$

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
template <typename T>
int s = 0, c = getchar();
x = 0;
while (isspace(c)) c = getchar();
if (c == 45) s = 1, c = getchar();
while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
if (s) x = -x;
}

template <typename T>
void write(T x, char c = ' ') {
int b[40], l = 0;
if (x < 0) putchar(45), x = -x;
while (x > 0) b[l++] = x % 10, x /= 10;
if (!l) putchar(48);
while (l) putchar(b[--l] | 48);
putchar(c);
}

const int N = 2e3+8;

char s[N][N];

LL up[N][N],down[N][N],l[N][N],r[N][N];

LL ans;

int n,m;

int main(void) {
for(int i = 0; i < n; ++ i){
scanf("%s",s[i]);
}
for(int i = 0; i < n; ++ i){
for(int sign=0,cnt=1,j = 0; j < m; ++ j){
if (s[i][j] != sign){
sign = s[i][j];
cnt = 0;
}
++cnt;
l[i][j] = cnt;
up[i][j] = down[i][j] = 1;
}
for(int sign=0,cnt=1,j = m-1; j >= 0; -- j){
if (s[i][j] != sign){
sign = s[i][j];
cnt = 0;
}
++cnt;
r[i][j] = cnt;
}
}
for(int i = 1; i < n; ++ i){
for(int j = 0; j < m; ++ j){
if (s[i][j] == s[i-1][j]){
up[i][j] = min(up[i-1][j] + 1, min(l[i][j], r[i][j]));
}
}
}
for(int i = n-1; i >= 0; -- i){
for(int j = 0; j < m; ++ j){
if (s[i][j] == s[i+1][j]){
down[i][j] = min(down[i+1][j] + 1, min(l[i][j], r[i][j]));
}
}
}
for(int i = 0; i < n; ++ i)
for(int j = 0; j < m; ++ j)
ans += min(up[i][j],down[i][j]);
write(ans,'\n');
return 0;
}


posted @ 2020-08-08 21:53  ~Lanly~  阅读(42)  评论(2编辑  收藏