题目链接: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的更多相关文章

  1. Codeforces Round #371 (Div. 2) B. Filya and Homework 水题

    B. Filya and Homework 题目连接: http://codeforces.com/contest/714/problem/B Description Today, hedgehog ...

  2. Codeforces Round #371 (Div. 1)

    A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. Codeforces Round #371 (Div. 2) D. Searching Rectangles 交互题 二分

    D. Searching Rectangles 题目连接: http://codeforces.com/contest/714/problem/D Description Filya just lea ...

  7. 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 ...

  8. Codeforces Round #371 (Div. 2) - B

    题目链接:http://codeforces.com/contest/714/problem/B 题意:给定一个长度为N的初始序列,然后问是否能找到一个值x,然后使得序列的每个元素+x/-x/不变,最 ...

  9. Codeforces Round #371 (Div. 2) - A

    题目链接:http://codeforces.com/contest/714/problem/A 题意:有两个人A,B 给定A的时间区间[L1,R1], B的时间区间[L2,R2],然后在正好K分钟的 ...

随机推荐

  1. android launchmode(四种启动模式)应用场景及实例

    模式介绍 [1] standard 模式 这是默认模式,每次激活Activity时都会创建Activity实例,并放入任务栈中. [2] singleTop 模式 如果在任务的栈顶正好存在该Activ ...

  2. php csv导出

    /** * 下载csv * @param unknown $orders_id * @param unknown $orders_date_start * @param unknown $orders ...

  3. 稻壳图文模块调不出html代码

    <?php doc_article('1',20,0,0,0,266,true,true,'id',0)?> 图文调用,倒数第三个参数,官方说是是否显示html代码,但是实测是没用的,不过 ...

  4. dede使用方法----如何调用最新文章,最热文章,友情链接

    dede如何调用最新文章 {dede:arclist      row='5'       titlelen='50'    orderby ='pubdate'} <li><a h ...

  5. 关于js中"window.location.href"、"location.href"、"parent.location.href"、"top.location.href"的用法

    location.href 和 window.location.href 区别: 1.location.href 可以直接跳转其他地址(不属于本项目) 也可以跳转本项目中的 2.window.loca ...

  6. 【BZOJ-3832】Rally 拓扑序 + 线段树 (神思路题!)

    3832: [Poi2014]Rally Time Limit: 20 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 168  Solved:  ...

  7. Jenkins配置MSBuild时使用环境变量

    [MSBuild Plugin]插件在使用环境变量有个很奇葩的方式,比如我们通常在Windows的节点机器上,使用WORKSPACE环境变量时,批处理应该这样写%WORKSPACE%,而有时插件确不能 ...

  8. dotnet反编译工具大全

    反编译不是为了破解软件,而是在开发时更好的读懂程序干了什么,比如MVC的源码,如果使用1和4的VS插件能更好的进行断点跟踪. 常用,效率最高: 1.[.NET Reflector]首选,能比较好的反编 ...

  9. Bzoj1449 [JSOI2009]球队收益

    Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 741  Solved: 423 Description Input Output 一个整数表示联盟里所有球 ...

  10. 动态库在线更新导致coredump的问题

    最近我们数据中心主机上的第三方管理工具升级,导致数据中心系统coredump,看起来不相关的事情,到底是怎么回事了? 首先,打开core文件看看: core.45259 is truncated: e ...