time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help.

Filya is given an array of non-negative integers a1, a2, ..., an.
First, he pick an integer x and then he adds x to
some elements of the array (no more than once), subtract x from some other elements (also, no more than once) and do no change other
elements. He wants all elements of the array to be equal.

Now he wonders if it's possible to pick such integer x and change some elements of the array using this x in
order to make all elements equal.

Input

The first line of the input contains an integer n (1 ≤ n ≤ 100 000) —
the number of integers in the Filya's array. The second line containsn integers a1, a2, ..., an (0 ≤ ai ≤ 109) —
elements of the array.

Output

If it's impossible to make all elements of the array equal using the process given in the problem statement, then print "NO" (without quotes) in the only line
of the output. Otherwise print "YES" (without quotes).

Examples
input
5
1 3 3 2 1
output
YES
input
5
1 2 3 4 5
output
NO
Note

In the first sample Filya should select x = 1, then add it to the first and the last elements of the array and subtract from the second
and the third elements.

【题解】

这题看上去很吓人。

但其实想想。如果有4个或以上不同的数字。就根本不可能满足条件嘛。

3个的话是有可能的。就是中间那个数是中位数。

排序。然后去重,统计有多少个不同的数字。

【代码】

#include <cstdio>
#include <algorithm> using namespace std; const int MAXN = 109000; int a[MAXN],n; void input_data()
{
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]);
} void get_ans()
{
sort(a + 1, a + 1 + n);
a[0] = 1;
for (int i = 2;i <= n;i++)
if (a[i] != a[i - 1])//这个去重方法是正确的
{
a[0]++;
a[a[0]] = a[i];
}
} void output_ans()
{
if (a[0] <= 2) //一个数也可以!
printf("YES\n");
else
if (a[0] == 3 && (a[1] + a[3]) == (a[2] * 2))
printf("YES\n");
else
printf("NO\n");
} int main()
{
//freopen("F:\\rush.txt", "r", stdin);
input_data();
get_ans();
output_ans();
return 0;
}

【31.95%】【CF 714B】Filya and Homework的更多相关文章

  1. 【codeforces】【比赛题解】#851 CF Round #432 (Div.2)

    cf真的难…… 点我浏览丧题. [A]Arpa和她对墨西哥人浪的研究 Arpa正在对墨西哥人浪进行研究. 有n个人站成一排,从1到n编号,他们从时刻0开始墨西哥人浪. 在时刻1,第一个人站起来.在时刻 ...

  2. LeetCode:下一个更大元素I【31】

    LeetCode:下一个更大元素I[31] 题目描述 给定两个没有重复元素的数组 nums1 和 nums2 ,其中nums1 是 nums2 的子集.找到 nums1 中每个元素在 nums2 中的 ...

  3. LeetCode:下一个排列【31】

    LeetCode:下一个排列[31] 题目描述 实现获取下一个排列的函数,算法需要将给定数字序列重新排列成字典序中下一个更大的排列. 如果不存在下一个更大的排列,则将数字重新排列成最小的排列(即升序排 ...

  4. 剑指Offer:栈的压入、弹出序列【31】

    剑指Offer:栈的压入.弹出序列[31] 题目描述 输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否为该栈的弹出顺序.假设压入栈的所有数字均不相等.例如序列1,2,3,4,5是某栈 ...

  5. 【CF 453A】 A. Little Pony and Expected Maximum(期望、快速幂)

    A. Little Pony and Expected Maximum time limit per test 1 second memory limit per test 256 megabytes ...

  6. 【Android】【录音】Android录音--AudioRecord、MediaRecorder

    [Android][录音]Android录音--AudioRecord.MediaRecorder Android提供了两个API用于实现录音功能:android.media.AudioRecord. ...

  7. 【开源】C#.NET股票历史数据采集,【附18年历史数据和源代码】

    如果用知乎,可以关注专栏:.NET开源项目和PowerBI社区 重点重点:我没有买股票,没有买股票,股市是个坑,小心割韭菜哦. 本文的初衷是数据分析(分析结果就不说了,就是想看看筛选点数据),只不过搞 ...

  8. 【微信小程序项目实践总结】30分钟从陌生到熟悉 web app 、native app、hybrid app比较 30分钟ES6从陌生到熟悉 【原创】浅谈内存泄露 HTML5 五子棋 - JS/Canvas 游戏 meta 详解,html5 meta 标签日常设置 C#中回滚TransactionScope的使用方法和原理

    [微信小程序项目实践总结]30分钟从陌生到熟悉 前言 我们之前对小程序做了基本学习: 1. 微信小程序开发07-列表页面怎么做 2. 微信小程序开发06-一个业务页面的完成 3. 微信小程序开发05- ...

  9. day41 python【事物 】【数据库锁】

    MySQL[五] [事物 ][数据库锁]   1.数据库事物 1. 什么是事务  事务是应用程序中一系列严密的操作,所有操作必须成功完成,否则在每个操作中所作的所有更改都会被撤消.也就是事务具有原子性 ...

随机推荐

  1. Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第二十一章:环境光遮蔽(AMBIENT OCCLUSION)

    原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第二十一章:环境光遮蔽(AMBIENT OCCLUSION) 学习目标 ...

  2. 配置一个Oracle共享服务器进程环境需要哪两项参数

    SHARED_SERVERS和DISPATCHERS. PROTOCOL(pro或prot): 调度程序要监听的网络协议.这是唯一必需的属性 ADDRESS(ADD或者ADDR): 指定调度程序正在上 ...

  3. SDUT-2144_最小生成树

    数据结构实验之图论九:最小生成树 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 有n个城市,其中有些城市之间可以修建公 ...

  4. MUI - sortable在mui.js前端框架不兼容的解决方案

    关于sortable看这 兼容的解决方案看这 http://www.cnblogs.com/phillyx/ 示例代码已更到github

  5. iphone开发中使用nib(xib)文件的内存管理

    iphoneuinavigationcontrollercocoauiviewvariableswindows 在使用nib文件做界面开发的过程中,加载nib文件后,由于设置了outlet和deleg ...

  6. JAVA高级特性--String/StringBuffer/Builder

    String String对象一旦创建就不能改变 是常量 需要进行大量字符串操作应采用StringBuffer/StringBuilder  最终结果转换成String对象 StringBuffer ...

  7. python 终端编码

  8. Java练习 SDUT-3081_谁是最强女汉子

    谁是最强的女汉子 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 众所周知,一年一度的女汉子大赛又来啦.由于最近女汉子比 ...

  9. 一维数组的初始化及遍历 Day06

    package com.sxt.arraytest1; import java.util.Arrays; /* * 一维数组 */ public class ArrayTest2 { public s ...

  10. @codechef - SONATR@ Sonya and Tree

    目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定 p 为 0~N-1 的一个排列,并给定一棵 N 个点的树. ...