Codeforce 296A - Yaroslav and Permutations
Yaroslav has an array that consists of n integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would be distinct in a finite time.
Help Yaroslav.
The first line contains integer n (1 ≤ n ≤ 100) — the number of elements in the array. The second line contains n integers a1, a2, ..., an(1 ≤ ai ≤ 1000) — the array elements.
In the single line print "YES" (without the quotes) if Yaroslav can obtain the array he needs, and "NO" (without the quotes) otherwise.
1
1
YES
3
1 1 2
YES
4
7 7 7 7
NO
In the first sample the initial array fits well.
In the second sample Yaroslav can get array: 1, 2, 1. He can swap the last and the second last elements to obtain it.
In the third sample Yarosav can't get the array he needs.
题解:统计出现次数最多的 如果大于一半 就不满足
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
ll gcd(ll a,ll b){
return b?gcd(b,a%b):a;
}
const int N=;
const int mod=1e9+;
bool flag=;
int a[N];
int main()
{
std::ios::sync_with_stdio(false);
int n,t;
cin>>n;
for(int i=;i<n;i++){
cin>>t;
a[t]++;
if(a[t]>(n+)/) flag=;
}
if(flag) cout<<"NO"<<endl;
else cout<<"YES"<<endl;
return ;
}
Codeforce 296A - Yaroslav and Permutations的更多相关文章
- Codeforces Round #179 (Div. 1 + Div. 2)
A. Yaroslav and Permutations 值相同的个数不能超过\(\lfloor \frac{n + 1}{2} \rfloor\). B. Yaroslav and Two Stri ...
- Permutations II
Given a collection of numbers that might contain duplicates, return all possible unique permutations ...
- [LeetCode] Permutations II 全排列之二
Given a collection of numbers that might contain duplicates, return all possible unique permutations ...
- [LeetCode] Permutations 全排列
Given a collection of numbers, return all possible permutations. For example,[1,2,3] have the follow ...
- POJ2369 Permutations(置换的周期)
链接:http://poj.org/problem?id=2369 Permutations Time Limit: 1000MS Memory Limit: 65536K Total Submi ...
- Permutations
Permutations Given a collection of distinct numbers, return all possible permutations. For example,[ ...
- 【leetcode】Permutations
题目描述: Given a collection of numbers, return all possible permutations. For example, [1,2,3] have the ...
- [leetcode] 47. Permutations II
Given a collection of numbers that might contain duplicates, return all possible unique permutations ...
- Leetcode Permutations
Given a collection of numbers, return all possible permutations. For example,[1,2,3] have the follow ...
随机推荐
- [MySQL优化2]不用SELECT * FROM table;
假设有一张employees表,它有8列:员工人数,姓氏,名字,分机,电子邮件,办公室代码,报告,职位等.如果要仅查看员工的名字,姓氏和职位,请使用以下查询:SELECT lastname, firs ...
- 20170927 Webservice发布指定账户进行访问
1. 搭建IIS 平台 于服务器A1 2.发布Webservice 到A1 我的问题在于(Webservice中方法中内容会对B1服务器的共享路径进行写入文件动作), 如何来控制网页使用特定的账户去访 ...
- Python3学习之路~6.2 实例演示面向对象编程的好处
首先建一个dog类,实例化为3个dog对象,并让它们都叫. class Dog: def bulk(self): print("xiaohuang:wang wang wang !" ...
- sqlserver2008出现数据库主体在该数据库中拥有架构,无法删除的解决方案
当要删除数据库中的某个用户名的时候会报错 出现数据库主体在该数据库中拥有架构,无法删除的解决方案(MicrosoftSQLServer,错误:15138) 和sql server2000不同 第一:这 ...
- 对比损失(Contrastive Loss)学习【转载】
转自:https://blog.csdn.net/autocyz/article/details/53149760 https://www.tensorflow.org/tutorials/repre ...
- Python复习基础篇
4.4 使用列表的一部分 Python切片(切片就是取值的呗) print(players[0:3]) 中括号,冒号隔开,顾头不顾尾. print([:4]) 从开始取还是会顾尾的 pri ...
- git checkout .还可以恢复吗
说实话,希望很渺茫, 如果你在git checkout . 之前操作了git stash ,还是可以恢复的,操作如下: 最后修改文件恢复了! 但是如果你在git checkout .之前没有git ...
- iOS 设计模式-NSNotificationCenter 通知中心
通知介绍 每一个应用程序都有一个通知中心(NSNotificationCenter)实例,专门负责协助不同对象之间的消息通信 任何一个对象都可以向通知中心发布通知(NSNotification),描述 ...
- iOS 开发笔记-NSURLConnection的使用
通过NSURLConnection发送一个HTTP GET请求 //send a GET request to server with some params -(void)httpGetWithPa ...
- Python实现selenium回放时间设置
一般在做selenium时会有,回放快慢的需求. 实现思路: 1.一般写selenium会自定义findelement函数,来实现查找元素. 2.在查找函数上加个睡眠时间的装饰器,函数执行完等待若干秒 ...