Codeforces Beta Round #94 div 1 D Numbers map+思路
2 seconds
256 megabytes
standard input
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?
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.
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).
4
1 2 3 2
YES
6
1 1 2 2 2 3
YES
6
2 4 1 1 2 2
NO
题意:给你n个数,围成环,相邻的两个数相差1;成立yes,否则no;
思路:设得到得环为b数组,b[0]=最大值;如果map中有b[i-1]-1,取b[i-1]-1;否则取b[i-1]+1,没有就输出no;
最后特判b数组的最前面的数和最后面的数;(不要问我怎么证明,我不会,想了下可以就拍了一发,居然a了);
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
#define true ture
#define false flase
using namespace std;
#define ll __int64
#define inf 0xfffffff
int scan()
{
int res = , ch ;
while( !( ( ch = getchar() ) >= '' && ch <= '' ) )
{
if( ch == EOF ) return << ;
}
res = ch - '' ;
while( ( ch = getchar() ) >= '' && ch <= '' )
res = res * + ( ch - '' ) ;
return res ;
}
map<int,int>m;
int a[];
int b[];
int main()
{
int x,y,z,i,t=;
scanf("%d",&x);
for(i=;i<x;i++)
{
scanf("%d",&a[i]);
m[a[i]]++;
t=max(t,a[i]);
}
b[]=t;
m[t]--;
int ans=;
for(i=;i<x;i++)
{
if(m[b[i-]-])
{
b[i]=b[i-]-;
m[b[i-]-]--;
}
else if(m[b[i-]+])
{
b[i]=b[i-]+;
m[b[i-]+]--;
}
else
{
ans=;
break;
}
}
if(b[]-b[x-]!=)
ans=;
if(ans)
printf("NO\n");
else
printf("YES\n");
return ;
}
Codeforces Beta Round #94 div 1 D Numbers map+思路的更多相关文章
- 图论/暴力 Codeforces Beta Round #94 (Div. 2 Only) B. Students and Shoelaces
题目传送门 /* 图论/暴力:这是个连通的问题,每一次把所有度数为1的砍掉,把连接的点再砍掉,总之很神奇,不懂:) */ #include <cstdio> #include <cs ...
- BFS Codeforces Beta Round #94 (Div. 2 Only) C. Statues
题目传送门 /* BFS:三维BFS,坐标再加上步数,能走一个点当这个地方在步数内不能落到.因为雕像最多8步就会全部下落, 只要撑过这个时间就能win,否则lose */ #include <c ...
- Codeforces Beta Round #94 div 2 B
B. Students and Shoelaces time limit per test 2 seconds memory limit per test 256 megabytes input st ...
- Codeforces Beta Round #94 (Div. 1 Only)B. String sam
题意:给你一个字符串,找第k大的子字符串.(考虑相同的字符串) 题解:建sam,先预处理出每个节点的出现次数,然后处理出每个节点下面的出现次数,然后在dfs时判断一下往哪边走即可,注意一下num会爆i ...
- Codeforces Beta Round #94 div 2 C Statues dfs或者bfs
C. Statues time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...
- Codeforces Beta Round #76 (Div. 2 Only)
Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
- Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...
- Codeforces Beta Round #79 (Div. 2 Only)
Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...
随机推荐
- Android下基于线程池的网络访问基础框架
引言 现在的Android开发很多都使用Volley.OkHttp.Retrofit等框架,这些框架固然有优秀的地方(以后会写代码学习分享),但是我们今天介绍一种基于Java线程池的网络访问框架. 实 ...
- cocos代码研究(2)Label学习笔记
理论部分 Label类继承自Node类,中文翻译文字与字体,通常在应用开发中为模块作为提示和描述的作用,主要有3中不同的创建方式. 1.通过ttf字体包创建,通过指定本地已有的ttf格式的字体文件,创 ...
- KM算法模板
大白书P248有证明,此处贴出两种复杂度的方案, n^4 大白书P350 n^3 #include <algorithm> #include <string.h> #inclu ...
- CPU VS GPU(性能调优 12.1)
CPU VS GPU 关于绘图和动画有两种处理的方式:CPU(中央处理器)和GPU(图形处理器).在现代iOS设备中,都有可以运行不同软件的可编程芯片,但是由于历史原因,我们可以说CPU所做的工作都在 ...
- linux常用命令:scp 命令
scp(secure copy)用于进行远程文件拷贝. 1.命令格式: scp [参数] [源文件] [目标文件] 2.命令功能: scp在主机间复制文件,他使用 ssh(1)作为数据传输,而且用同样 ...
- LoadRunner 自动关联、手动关联的帖子
https://www.guru99.com/correlation-in-loadrunner-ultimate-guide.html 这个网页里介绍了关联的概念,自动关联和手动关联的知识...
- Linux中Postfix邮件接收配置(四)
Dovecot介绍 MRA邮件取回代理也有很多如courier-imap,cyrus-imap和dovecot这三个个工具,下面重点介绍Dovecot: 1.高安全性.据 Dovecot 的作者声称, ...
- Nginx能做什么
本文只针对Nginx在不加载第三方模块的情况能处理哪些事情,由于第三方模块太多所以也介绍不完,当然本文本身也可能介绍的不完整,毕竟只是我个人使用过和了解到过得.所以还请见谅,同时欢迎留言交流. Ngi ...
- PHP安装Xdebug扩展并配置PHPstorm调试(Centos、Windows)
一.给PHP安装Xdebug扩展 [windows] 废话不多说,直接上代码上方法安装扩展,我这里是在windows下. 首先需要确定的就是对应的PHP版本安装对应的Xdebug扩展文件,提供一个最快 ...
- linux查看内存free
free 加参数-b/k//m/g,以b.k.m.g的大小显示结果,默认以k显示 [root@oldboy ~]# free total used free shared buffers cached ...