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. ip分片重组 ip_defrag

    在ip_local_deliver中,如果检测到是分片包,则需要进行分片重组: ip_local_deliver |-->ip_is_fragment //判断是否为分片包 |-->ip_ ...

  2. 企业日志大数据分析系统ELK+KAFKA实现【转】

    背景: 最近线上上了ELK,但是只用了一台Redis在中间作为消息队列,以减轻前端es集群的压力,Redis的集群解决方案暂时没有接触过,并且Redis作为消息队列并不是它的强项:所以最近将Redis ...

  3. IntelliJ IDEA 里 查看一个函数注释的方法是 ctrl+q

     ctrl + q 也可以看到 官方的文档注释,java真是个强大的东西,官方的每个函数都有注释,这些注释 自动生成了官方的文档,所以看官方的注释 就是 看 官方的文档.

  4. SQLServer判断指定列的默认值是否存在,并修改默认值

    SQLServer判断指定列的默认值是否存在,并修改默认值 2008年10月21日 星期二 下午 12:08 if exists(select A.name as DefaultName,B.name ...

  5. Knockout应用开发指南 应用举例(简单、高级)

    Knockout应用开发指南 第八章:简单应用举例(1)http://www.cnblogs.com/TomXu/archive/2011/11/30/2257067.htmlKnockout应用开发 ...

  6. 使用mongo-java-driver-3.0.2连接MongoDB数据库

    这里使用的mongodb的java驱动版本是:3.0.2,文件名mongo-java-driver-3.0.2.jar  博客本地下载下载网址(也可以下载其它版本):http://central.ma ...

  7. GUC-7 同步锁 Lock

    import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; /* * 一.用于解决 ...

  8. .size和.empty

    坑爹的list容器size方法--为了splice居然把复杂度设计为O(N)? 能用empty的时候,不要用size empty可以保证常量复杂度,但list的size不保证 链表长度必须要遍历全部的 ...

  9. USACO 5.3 Window Area

    Window AreaIV Balkan Olympiad You've just be assigned the project of implemented a windowing interfa ...

  10. Loadrunner11在win7下录制脚本,ie打不开

    Loadrunner11在win7下录制脚本,ie打不开 使用loadrunner11录制脚本时试了很多办法都无法打开ie浏览器,最后终于解决了 1.ie浏览器去掉启用第三方浏览器扩展 2.loadr ...