Codeforces Round #371 (Div. 2)B. Filya and Homework
题目链接:http://codeforces.com/problemset/problem/714/B
题目大意:
第一行输入一个n,第二行输入n个数,求是否能找出一个数x,使得n个数中的部分数加上x或部分数减去x ,n个数相等。
例如:5
1 3 3 2 1
输出:
YES
Init:
x=1 情况,第一个数和最后一个数+x,第二三个数减去x ,则这n个数都为2(相等),故输出“YES”
解题思路:
对于刚才举的例子 可知 n个数只有三个元素 1 2 3 只要使得 2-1==3-2 即可满足条件
用一个数组存储n 个数,进行排序和查重。
如果查重后的元素<=2 即只有一个元素或两个元素则肯定满足条件输出“YES”
或者查重后的元素有三个 且 narr[1]-narr[0]==narr[2]-narr[1] (这里用到了排序) 则也输出“YES”
其他情况输出NO.
AC Code:
#include<bits/stdc++.h>
using namespace std;
int na[];
int main()
{
int n,i;
while(scanf("%d",&n)!=EOF)
{
for(i=; i<n; i++)
scanf("%d",&na[i]);
sort(na,na+n);
int cut=unique(na,na+n)-na;
if(cut<=||(cut==&&(na[]-na[]==na[]-na[])))
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return ;
}
Codeforces Round #371 (Div. 2)B. Filya and Homework的更多相关文章
- Codeforces Round #371 (Div. 2) B. Filya and Homework 水题
B. Filya and Homework 题目连接: http://codeforces.com/contest/714/problem/B Description Today, hedgehog ...
- Codeforces Round #371 (Div. 1)
A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...
- Codeforces Round #371 (Div. 2)(set\unique)
B. Filya and Homework time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Codeforces Round #371 (Div. 2) A ,B , C 水,水,trie树
A. Meeting of Old Friends time limit per test 1 second memory limit per test 256 megabytes input sta ...
- Codeforces Round #371 (Div. 1) D. Animals and Puzzle 二维倍增
D. Animals and Puzzle 题目连接: http://codeforces.com/contest/713/problem/D Description Owl Sonya gave a ...
- Codeforces Round #371 (Div. 2) D. Searching Rectangles 交互题 二分
D. Searching Rectangles 题目连接: http://codeforces.com/contest/714/problem/D Description Filya just lea ...
- Codeforces Round #371 (Div. 2) A. Meeting of Old Friends 水题
A. Meeting of Old Friends 题目连接: http://codeforces.com/contest/714/problem/A Description Today an out ...
- Codeforces Round #371 (Div. 2) - B
题目链接:http://codeforces.com/contest/714/problem/B 题意:给定一个长度为N的初始序列,然后问是否能找到一个值x,然后使得序列的每个元素+x/-x/不变,最 ...
- Codeforces Round #371 (Div. 2) - A
题目链接:http://codeforces.com/contest/714/problem/A 题意:有两个人A,B 给定A的时间区间[L1,R1], B的时间区间[L2,R2],然后在正好K分钟的 ...
随机推荐
- C++折半插入排序
代码如下: #include <iostream> using namespace std; void insertSort(int a[], int n) { for(int i=1;i ...
- 切割haproxy的日志
日志的切割有以下几种方法: 1.写个定时任务,每天某个时间点把旧的日志重命名,并对服务重启使其重新打开日志并写入. 2.通过管道的方式把新产生的日志写到另外一个日志文件里. 3.通过logrotate ...
- 侧滑菜单SlidingMenu
想要使用SlidingMenu 需要下载文件SlidingMenu-master 并导入SlidingMenu-master中的第三方library 如图所示: 修改library里的build.gr ...
- Win7另存文件没有桌面的解决方法
今日一朋友保存文件随口说了一句我那个桌面找不到了...我略感惊奇,没遇到这么个情况.决定,问度娘,在此做下记录,以便以后自己或朋友查阅. 我们在网上另存一个文件,打开另存窗口,发现没有“桌面” 在收藏 ...
- HTTP/2.0与HTTP/1.1协议区别
超文本传输协议(英文:HyperText Transfer Protocol,缩写:HTTP)是互联网上应用最为广泛的一种网络协议.设计HTTP最初的目的是为了提供一种发布和接收HTML页面的方法.通 ...
- 「个人vim插件+配置」
2016.10.4 filetype indent on syntax on set nu ai ci si set sw= ts= set autochdir set backspace= colo ...
- 【Gym 100947C】Rotate It !!
分两类,奇数和偶数的,用隔项前缀和算一下. #include <algorithm> #include <iostream> #define N 10005 using nam ...
- UITextView实现placeHolder方法汇总
UITextField中有一个placeholder属性,可以设置UITextField的占位文字,起到提示用户的作用.可是UITextView就没那么幸运了,apple没有给UITextView提供 ...
- python第一天
python 解释器执行代码有两种 一种在解释器: win+R==>cmd 打开终端进行 输入python 加 路径 另一种在文件里写完再到解释器执行:win+R==>cmd 打开终端进行 ...
- Linux基础1
1.Linux文件系统类型 ext2 ext3(rhel5) ext4(rhel6) lvm raid swap gfs nfs vfat 2.linux 系统通过磁盘接口识别磁盘 IDE接口 hda ...