【31.95%】【CF 714B】Filya and Homework
1 second
256 megabytes
standard input
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.
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.
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).
5
1 3 3 2 1
YES
5
1 2 3 4 5
NO
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的更多相关文章
- 【codeforces】【比赛题解】#851 CF Round #432 (Div.2)
cf真的难…… 点我浏览丧题. [A]Arpa和她对墨西哥人浪的研究 Arpa正在对墨西哥人浪进行研究. 有n个人站成一排,从1到n编号,他们从时刻0开始墨西哥人浪. 在时刻1,第一个人站起来.在时刻 ...
- LeetCode:下一个更大元素I【31】
LeetCode:下一个更大元素I[31] 题目描述 给定两个没有重复元素的数组 nums1 和 nums2 ,其中nums1 是 nums2 的子集.找到 nums1 中每个元素在 nums2 中的 ...
- LeetCode:下一个排列【31】
LeetCode:下一个排列[31] 题目描述 实现获取下一个排列的函数,算法需要将给定数字序列重新排列成字典序中下一个更大的排列. 如果不存在下一个更大的排列,则将数字重新排列成最小的排列(即升序排 ...
- 剑指Offer:栈的压入、弹出序列【31】
剑指Offer:栈的压入.弹出序列[31] 题目描述 输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否为该栈的弹出顺序.假设压入栈的所有数字均不相等.例如序列1,2,3,4,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 ...
- 【Android】【录音】Android录音--AudioRecord、MediaRecorder
[Android][录音]Android录音--AudioRecord.MediaRecorder Android提供了两个API用于实现录音功能:android.media.AudioRecord. ...
- 【开源】C#.NET股票历史数据采集,【附18年历史数据和源代码】
如果用知乎,可以关注专栏:.NET开源项目和PowerBI社区 重点重点:我没有买股票,没有买股票,股市是个坑,小心割韭菜哦. 本文的初衷是数据分析(分析结果就不说了,就是想看看筛选点数据),只不过搞 ...
- 【微信小程序项目实践总结】30分钟从陌生到熟悉 web app 、native app、hybrid app比较 30分钟ES6从陌生到熟悉 【原创】浅谈内存泄露 HTML5 五子棋 - JS/Canvas 游戏 meta 详解,html5 meta 标签日常设置 C#中回滚TransactionScope的使用方法和原理
[微信小程序项目实践总结]30分钟从陌生到熟悉 前言 我们之前对小程序做了基本学习: 1. 微信小程序开发07-列表页面怎么做 2. 微信小程序开发06-一个业务页面的完成 3. 微信小程序开发05- ...
- day41 python【事物 】【数据库锁】
MySQL[五] [事物 ][数据库锁] 1.数据库事物 1. 什么是事务 事务是应用程序中一系列严密的操作,所有操作必须成功完成,否则在每个操作中所作的所有更改都会被撤消.也就是事务具有原子性 ...
随机推荐
- 关于JSP的淘汰问题(转)
来源:http://1t.click/peD 大中型公司需要专业人才,小公司需要全才,但是对于个人职业发展来说,我建议是分开.你要是这辈子就吃java这碗饭,就不要去研究什么css,js等等. 把你的 ...
- PLAY2.6-SCALA(十) 模板引擎Twirl
一.语法 1.@ 它是一个特殊的字符,表示动态声明的开始.对于简单的动态声明结尾可以从代码块中自动推断结尾,对于复杂的表达式通常加上() Hello @(customer.firstName + cu ...
- 微信小程序开发资源整理
有兴趣学习微信小程序开发的可以关注简书专题 微信小程序开发 由于微信已经开发文档和开发工具了,所以下面的内容用处不大了. 具体参考:http://mp.weixin.qq.com/wiki/ 这篇文章 ...
- 使用 EnumWindows 找到满足你要求的窗口 - walterlv
原文:使用 EnumWindows 找到满足你要求的窗口 - walterlv 使用 EnumWindows 找到满足你要求的窗口 2019-04-30 13:11 在 Windows 应用开发中,如 ...
- C++与JAVA代码实现CRC-16/MODBUS算法,且与 http://www.ip33.com/crc.html 进行结果验证
CRC-16/MODBUS的多项式为:x16+x15+x2+1(8005),宽度为16.运算时,首先将一个16位的寄存器预置为11111111 11111111,然后连续把数据帧中的每个字节中的8位与 ...
- websocket实现五子棋联机对战
GoBang.html // 对弈的页面 <!DOCTYPE html> <html> <head> <meta charset="UTF-8&qu ...
- 12 将类处理为excel,再将excel处理为类(界限计划3)
中间使用map作为中间处理 将类处理为excel: 1.读取类转为map //读取btl,转为map public static Map getBtlMap(String rule, BTLDAO b ...
- 洛谷P1546 最短网络 Agri-Net(Prim堆优化)
#include<bits/stdc++.h> using namespace std; ; const int INF=0x3f3f3f3f; inline void read(int ...
- How do I cover the “no results” text in UISearchDisplayController's searchResultTableView?
How do I cover the "no results" text in UISearchDisplayController's searchResultTableView? ...
- @codechef - SERSUM@ Series Sum
目录 @description@ @solution@ @part - 1@ @part - 2@ @part - 3@ @accepted code@ @details@ @description@ ...