题目链接: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. [转]response.getWriter().write()与out.print()的区别

    原文地址:http://blog.csdn.net/javaloveiphone/article/details/8133772 1.首先介绍write()和print()方法的区别:   (1).w ...

  2. Hibernate @Formula 注解方式

    1.Formula的作用 Formula的作用就是用一个查询语句动态的生成一个类的属性 就是一条select count(*)...构成的虚拟列,而不是存储在数据库里的一个字段.用比较标准的说法就是: ...

  3. 回到顶端js实现

    function goTop(){ var _btn = document.getElementById("goTop"); if (document.documentElemen ...

  4. TopCoder SRM 596 DIV 1 250

    body { font-family: Monospaced; font-size: 12pt } pre { font-family: Monospaced; font-size: 12pt } P ...

  5. js-JavaScript高级程序设计学习笔记2

    第四章 变量.作用域和内存问题 1.ES变量包含两种不同数据类型的值--基本类型值(5种基本数据类型)和引用类型值(保存在内存中的对象,所有引用类型值都是Object的实例) 2.只能给引用类型值动态 ...

  6. 关于使用struts2时子窗体页面跳转后在父窗体打开的问题以及Session过期后的页面跳转问题

    问题1:传统的系统界面,iframe了三个页面,上,左,右,用户点击注销的按钮在上面得top.jsp里面,方法:<a href="../adminAction/admin_logout ...

  7. 【BZOJ-2725】故乡的梦 Dijsktra + Tarjan + Dinic + BFS + 堆

    2725: [Violet 6]故乡的梦 Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 502  Solved: 173[Submit][Status ...

  8. macOS 安装 wget

    适用于macOS Sierra Apple Store下载安装Xcode 安装Homebrew包管理,类似于Ubuntu下的apt-get: 终端下输入 ruby -e "$(curl -f ...

  9. springMVC-mvc:annotation-driven

    <mvc:annotation-driven/>会自动注册 RequestMappingHandlerMapping RequestMappingHandlerAdapter Except ...

  10. linux挂载远程samba目录

    yum install cifs-utils  #安装cifs协议包 #列出远程目录 smbclient -L 192.100.9.165 -Uadministrator vim /etc/fstab ...