D. Numbers
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

One day Anna got the following task at school: to arrange several numbers in a circle so that any two neighboring numbers differs exactly by 1. Anna was given several numbers and arranged them in a circle to fulfill the task. Then she wanted to check if she had arranged the numbers correctly, but at this point her younger sister Maria came and shuffled all numbers. Anna got sick with anger but what's done is done and the results of her work had been destroyed. But please tell Anna: could she have hypothetically completed the task using all those given numbers?

Input

The first line contains an integer n — how many numbers Anna had (3 ≤ n ≤ 105). The next line contains those numbers, separated by a space. All numbers are integers and belong to the range from 1 to 109.

Output

Print the single line "YES" (without the quotes), if Anna could have completed the task correctly using all those numbers (using all of them is necessary). If Anna couldn't have fulfilled the task, no matter how hard she would try, print "NO" (without the quotes).

Sample test(s)
Input
4
1 2 3 2
Output
YES
Input
6
1 1 2 2 2 3
Output
YES
Input
6
2 4 1 1 2 2
Output
NO
题面意思:
大概就是讲有n张牌,这N张牌需要围成一个圈,要求牌和他相邻的牌最多相差1
问可不可行 思路:大概就是缩吧,比如 121可以看成1,12121也可以看成1。
在草稿本上画画就可以知道,最后状态是类似于12这种环
当然,出现断链的时候,当然是不可行的啦
于是就乱搞吧= =
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 100001
const int inf=0x7fffffff; //无限大
int a[maxn];
int t[maxn];
int main()
{
int n;
while(cin>>n){
cin>>a[];
int mi=a[];
for(int i=;i<n;i++)
{
cin>>a[i];
mi=min(a[i],mi);
}
sort(a,a+n);
int flag=; for(int i=;i<n;i++)
{
if(a[i]-mi>=maxn)
{
flag=;
break;
}
t[a[i]-mi]++;
} if(flag==)
for(int i=;i<a[n-]-mi+;i++)
{
//cout<<t[i]<<endl;
if(t[i]==)
{
flag=;
break;
}
if(i!=a[n-]-mi&&t[i]<=t[i-])
{
flag=;
break;
}
if(i==a[n-]-mi&&t[i]!=t[i-])
{
flag=;
break;
}
t[i]-=t[i-];
}
if(flag==)
cout<<"NO"<<endl;
else
cout<<"YES"<<endl;
}
return ;
}
												

CodeForces 128D Numbers 构造的更多相关文章

  1. codeforces 1041 e 构造

    Codeforces 1041 E 构造题. 给出一种操作,对于一棵树,去掉它的一条边.那么这颗树被分成两个部分,两个部分的分别的最大值就是这次操作的答案. 现在给出一棵树所有操作的结果,问能不能构造 ...

  2. Codeforces 410C.Team[构造]

    C. Team time limit per test 1 second memory limit per test 256 megabytes input standard input output ...

  3. Tea Party CodeForces - 808C (构造+贪心)

    Polycarp invited all his friends to the tea party to celebrate the holiday. He has ncups, one for ea ...

  4. Codeforces #55D-Beautiful numbers (数位dp)

    D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...

  5. Codeforces - 474D - Flowers - 构造 - 简单dp

    https://codeforces.com/problemset/problem/474/D 这道题挺好的,思路是这样. 我们要找一个01串,其中0的段要被划分为若干个连续k的0. 我们设想一个长度 ...

  6. Codeforces Global Round 4 Prime Graph CodeForces - 1178D (构造,结论)

    Every person likes prime numbers. Alice is a person, thus she also shares the love for them. Bob wan ...

  7. codeforces Beautiful Numbers

    来源:http://codeforces.com/problemset/problem/1265/B   B. Beautiful Numbers   You are given a permutat ...

  8. Codeforces Global Round 8 B. Codeforces Subsequences(构造)

    题目链接:https://codeforces.com/contest/1368/problem/B 题意 构造最短的至少含有 $k$ 个 $codeforces$ 子序列的字符串. 题解 如下表: ...

  9. Codeforces 716C[数论][构造]

    /* CF傻逼构造题 某人要经过n回合游戏,初始分值是2,等级为1. 每次有两种操作 1.无条件,分值加上自己的等级数. 2.当目前的数字是完全平方数并且该数字开方以后是等级数加1的整数倍,那么可以将 ...

随机推荐

  1. c++语言知识点汇总

    c++ primer version-5 的整理 section 1: 内置类型和自定义类型: main函数的返回值:指示状态.0:成功:1:系统定义. unix和win系统中,执行完程序可以使用ec ...

  2. 二十、springboot之jpa开发@MappedSuperclass 注解说明

    @MappedSuperclass使用条件: 当我们进行开发项目时,我们经常会用到实体映射到数据库表的操作,此时我们经常会发现在我们需要映射的几个实体类中,有几个共同的属性,例如编号ID,创建者,创建 ...

  3. python网络编程--线程event

    一:线程event作用 Python提供了Event对象用于线程间通信,它是线程设置的信号标志,如果信号标志位真,则其他线程等待直到信号结束. Event对象实现了简单的线程通信机制,它提供了设置信号 ...

  4. No.18 selenium学习之路之批量执行测试用例

    diascover方法,加载所有测试用例 1.discover方法里面有三个参数: -case_dir:测试用例的目录 -pattern:这个是匹配脚本名称的规则,test*.py意思是匹配test开 ...

  5. jenkins Error performing command: git ls-remote -h

    Jenkins新建项目中源码管理使用Git时遇到如下问题: Failed to connect to repository : Error performing command: git ls-rem ...

  6. java算法小例子

    作为一个程序员,有时候我觉得自己都不适合,因为自己数学不好,算法不好,脑子不够灵活.而对于算法,感觉就像是数学题,总觉得很难.以前上学,在班里总有几个什么都不好,但唯独数学很厉害,真气人!面对难题时, ...

  7. centos7 vnc 无法systemctl启动

    1.centos7 vnc 无法systemctl启动 报错如下:Failed to start Remote desktop service (VNC) 2.解决办法 错误服务脚本名 vncserv ...

  8. 在Kubernetes上使用Traefik

    本节内容: Traefik介绍 部署测试用的两个服务 Role Based Access Control configuration (Kubernetes 1.6+ only) 部署Traefik ...

  9. centos安装lspci工具

    https://blog.csdn.net/wudiyi815/article/details/38325199

  10. 【LOJ】#2105. 「TJOI2015」概率论

    题解 可以说是什么找规律好题了 但是要推生成函数,非常神奇-- 任何的一切都可以用\(n^2\)dp说起 我们所求即是 所有树的叶子总数/所有树的方案数 我们可以列出一个递推式,设\(g(x)\)为\ ...