AtCoder Grand Contest 016 B - Colorful Hats
题目传送门:https://agc016.contest.atcoder.jp/tasks/agc016_b
题目大意:
有\(N\)只猫,每只猫头上带着一个帽子,帽子有颜色,现在告诉你每只猫能看到的其他猫的帽子颜色种数\(a_i\),问是否可能
又是一个结论题……我们设\(Max=\max\limits_{i=1}^n\{a_i\},Min=\min\limits_{i=1}^n\{a_i\}\),若\(Max-Min>1\),则不可能,然后我们分两种情况讨论:
- \(Max=Min\),那么若\(Max\in(\lfloor\dfrac{n}{2}\rfloor,n-1)\bigcup[n,\infty)\),则不可能,否则可能(要么都独一无二,要么一种颜色至少出现两次)
- \(Max=Min+1\),那么对于\(i\in[1,n],a_i=Min\),它们的帽子颜色都独一无二的,因为不可能使得所有帽子颜色都独一无二,所以令\(Max'=Max-cnt[Min],n'=n-cnt[Min],cnt[Min]\)为\(Min\)出现次数,若\(Max'\in[1,\lfloor\dfrac{n'}{2}\rfloor]\),则可能,否则不可能
/*program from Wolfycz*/
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define inf 0x7f7f7f7f
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
inline char gc(){
static char buf[1000000],*p1=buf,*p2=buf;
return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
}
inline int frd(){
int x=0,f=1; char ch=gc();
for (;ch<'0'||ch>'9';ch=gc()) if (ch=='-') f=-1;
for (;ch>='0'&&ch<='9';ch=gc()) x=(x<<3)+(x<<1)+ch-'0';
return x*f;
}
inline int read(){
int x=0,f=1; char ch=getchar();
for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
for (;ch>='0'&&ch<='9';ch=getchar()) x=(x<<3)+(x<<1)+ch-'0';
return x*f;
}
inline void print(int x){
if (x<0) putchar('-'),x=-x;
if (x>9) print(x/10);
putchar(x%10+'0');
}
const int N=1e5;
int v[N+10];
int main(){
int n=read(),Max=-inf,Min=inf;
for (int i=1;i<=n;i++){
v[i]=read();
Max=max(Max,v[i]);
Min=min(Min,v[i]);
}
if (Max-Min>1) printf("No\n");
if (Max==Min) printf(Max==n-1||Max<=n>>1?"Yes\n":"No\n");
if (Max==Min+1){
int cnt=0;
for (int i=1;i<=n;i++) if (v[i]==Min) cnt++;
n-=cnt,Max-=cnt;
printf(Max>0&&Max<=n>>1?"Yes\n":"No\n");
}
return 0;
}
AtCoder Grand Contest 016 B - Colorful Hats的更多相关文章
- AtCoder Grand Contest 016
在雅礼和衡水的dalao们打了一场atcoder 然而窝好菜啊…… A - Shrinking 题意:定义一次操作为将长度为n的字符串变成长度n-1的字符串,且变化后第i个字母为变化前第i 或 i+1 ...
- AtCoder Grand Contest 016 E - Poor Turkeys
题目传送门:https://agc016.contest.atcoder.jp/tasks/agc016_e 题目大意: 有\(N\)只火鸡,现有\(M\)个人,每个人指定了两只火鸡\(x,y\),每 ...
- AtCoder Grand Contest 016 C - +/- Rectangle
题目传送门:https://agc016.contest.atcoder.jp/tasks/agc016_c 题目大意: 给定整数\(H,W,h,w\),你需要判断是否存在满足如下条件的矩阵,如果存在 ...
- AtCoder Grand Contest 016 F - Games on DAG
题目传送门:https://agc016.contest.atcoder.jp/tasks/agc016_f 题目大意: 给定一个\(N\)点\(M\)边的DAG,\(x_i\)有边连向\(y_i\) ...
- Atcoder Grand Contest 016 F - Games on DAG(状压 dp)
洛谷题面传送门 & Atcoder 题面传送门 如何看待 tzc 补他一个月前做的题目的题解 首先根据 SG 定理先手必输当且仅当 \(\text{SG}(1)=\text{SG}(2)\). ...
- AtCoder Grand Contest #026 A - Colorful Slimes 2
Time Limit: 2 sec / Memory Limit: 1024 MB Score : 200200 points Problem Statement Takahashi lives in ...
- AtCoder Grand Contest 012 D Colorful Balls
题意: 有N个球排成一行,第i个球颜色为ci, 权为wi, 如果两个同色球权值和 <= X 则它们可以交换: 如果两个异色球权值和 <= Y 则它们可以交换:不限制交换次数,求能到达的颜色 ...
- AtCoder Grand Contest 016题解
传送门 \(A\) 直接枚举最终的字母然后模拟就行了-- 就这数据范围还是别学我写的这种做法了-- const int N=105; char s[N];int las[26],mx[26],n,re ...
- AtCoder Grand Contest 012
AtCoder Grand Contest 012 A - AtCoder Group Contest 翻译 有\(3n\)个人,每一个人有一个强大值(看我的假翻译),每三个人可以分成一组,一组的强大 ...
随机推荐
- HDU 6040 Hints of sd0061 nth_element函数
Hints of sd0061 Problem Description sd0061, the legend of Beihang University ACM-ICPC Team, retired ...
- SLG, 菱形格子的算法.(递归版
class GeoPoint{ public: int x; int y; public: bool operator == (const GeoPoint& p){ return p.x = ...
- Mac OS X 开发环境搭建之利用 Parallel Desktop 安装 CentOS 7 [转载]
背景 在企业级软件系统中,数据库的地位是比较高的,而且一般都要求支持多种数据库,如 Oracle. DB2.MySQL 等,它们的最新版本大多都不再支持 Mac OS X 系统,所以装一个 Linux ...
- php与html 表单的结合
PHP $_POST <!DOCTYPE html> <html> <body> <form method="post" action=& ...
- SDUT 3035 你猜我猜不猜你猜不猜(字符串 规律性)
你猜我猜不猜你猜不猜 Time Limit: 2000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 In the past 39th annual ACM in ...
- POJ1077 Eight —— 经典的搜索问题
题目链接:http://poj.org/problem?id=1077 Eight Time Limit: 1000MS Memory Limit: 65536K Total Submission ...
- Linux:NFS文件共享问题重新认识
之前也搭建过nfs,服务器之间目录里面的文件同享也一直正常.今天有现场反映,搭建nfs后,客户端文件在服务器端看不见. 在我之前的认识里,服务器端搭建好并启动nfs服务,客户端mount后,客户端.服 ...
- 自定义android 音乐通知栏 ——可伸缩扩展
Android custom notification for music player Example In this tutorial, you will learn how to creat ...
- POJ3020 二分图匹配——最小路径覆盖
Description The Global Aerial Research Centre has been allotted the task of building the fifth gener ...
- Cocos2dx+lua合适还是Cocos2dx+js合适?
问题: 开发cocos2dx手游Cocos2dx+lua合适还是Cocos2dx+js合适 百牛信息技术bainiu.ltd整理发布于博客园 回答: 作者:廖宇雷链接:https://www.zhih ...