# AT2386 Colorful Hats (乱搞题,思维题)

max不等于min + 1 或者不等于min,这种情况显然不存在.

n : 人数

max : 能看到最多的颜色. (总颜色)
max - 1 : 本身是独立的颜色

max - cnt就是剩下的颜色个数

#include <iostream>
#include <cstdio>
#define gc getchar()
#define pc putchar
#define rep(i,x,p) for(int i = x;i <= p;++ i)
#define sep(i,x,p) for(int i = x;i >= p;-- i)
using namespace std;
const int maxN = 1e5 + 7;

int a[maxN];

int x = 0 ,f = 1;char c = gc;
while(c < '0' || c > '9') {if(c == '-')f = -1;c = gc;}
while(c >= '0' && c <= '9') {x = x * 10 + c - '0';c = gc;}
return x * f;
}

void print(int x) {
if(x < 0) {
pc('-');
x = -x;
}
if(x >= 10) print(x / 10);
pc(x % 10 + '0');
}

int main() {
int n,maxx = 0, minn = 1e6;
rep(i,1,n) maxx = max(maxx,a[i]);
rep(i,1,n) minn = min(minn,a[i]);
if(maxx != minn + 1 && maxx != minn)  {puts("No");return 0;}
if(maxx == minn) {
if(a[1] == n - 1 || 2 * a[1] <= n) puts("Yes");
else puts("No");
return 0;
}
int cnt = 0;
rep(i , 1 , n) if(a[i] == minn) cnt ++;
if(cnt >= maxx || 2 * (maxx - cnt) > n - cnt) puts("No");
else puts("Yes");
return 0;
}

posted @ 2018-10-19 21:15  Rlif  阅读(181)  评论(1编辑  收藏  举报