Codeforces Round #402 (Div. 2) A
Description
In Berland each high school student is characterized by academic performance — integer value between 1 and 5.
In high school 0xFF there are two groups of pupils: the group A and the group B. Each group consists of exactly n students. An academic performance of each student is known — integer value between 1 and 5.
The school director wants to redistribute students between groups so that each of the two groups has the same number of students whose academic performance is equal to 1, the same number of students whose academic performance is 2 and so on. In other words, the purpose of the school director is to change the composition of groups, so that for each value of academic performance the numbers of students in both groups are equal.
To achieve this, there is a plan to produce a series of exchanges of students between groups. During the single exchange the director selects one student from the class A and one student of class B. After that, they both change their groups.
Print the least number of exchanges, in order to achieve the desired equal numbers of students for each academic performance.
The first line of the input contains integer number n (1 ≤ n ≤ 100) — number of students in both groups.
The second line contains sequence of integer numbers a1, a2, ..., an (1 ≤ ai ≤ 5), where ai is academic performance of the i-th student of the group A.
The third line contains sequence of integer numbers b1, b2, ..., bn (1 ≤ bi ≤ 5), where bi is academic performance of the i-th student of the group B.
Print the required minimum number of exchanges or -1, if the desired distribution of students can not be obtained.
4
5 4 4 4
5 5 4 5
1
6
1 1 1 1 1 1
5 5 5 5 5 5
3
1
5
3
-1
9
3 2 5 5 2 3 3 3 2
4 1 4 1 1 2 4 4 1
4
题意:交换两个组的学生,使得两个组的分数相同。
解法:自然需要符合一个分数出现次数为偶数,如果出现奇数不能平分。
然后计算两个组出现相同分数之差除以2,求得和/2就是结果
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int maxn=;
int a[],b[];
map<int,int>p,q;
int main()
{
int n;
cin>>n;
for(int i=;i<=n;i++)
{
cin>>a[i];
q[a[i]]++;
}
for(int i=;i<=n;i++)
{
cin>>b[i];
p[b[i]]++;
}
int ans=;
for(int i=;i<=;i++)
{
if((p[i]+q[i])%)
{
cout<<"-1";
return ;
}
else
{
ans+=abs(p[i]-q[i])/;
}
}
cout<<ans/<<endl;
return ;
}
Codeforces Round #402 (Div. 2) A的更多相关文章
- Codeforces Round #402 (Div. 2)
Codeforces Round #402 (Div. 2) A. 日常沙比提 #include<iostream> #include<cstdio> #include< ...
- Codeforces Round #402 (Div. 2) A+B+C+D
Codeforces Round #402 (Div. 2) A. Pupils Redistribution 模拟大法好.两个数列分别含有n个数x(1<=x<=5) .现在要求交换一些数 ...
- Codeforces Round #402 (Div. 2) A,B,C,D,E
A. Pupils Redistribution time limit per test 1 second memory limit per test 256 megabytes input stan ...
- Codeforces Round #402 (Div. 2) D. String Game
D. String Game time limit per test 2 seconds memory limit per test 512 megabytes input standard inpu ...
- Codeforces Round #402 (Div. 2) A B C sort D二分 (水)
A. Pupils Redistribution time limit per test 1 second memory limit per test 256 megabytes input stan ...
- 【DFS】Codeforces Round #402 (Div. 2) B. Weird Rounding
暴搜 #include<cstdio> #include<algorithm> using namespace std; int n,K,Div=1,a[21],m,ans=1 ...
- Codeforces Round #402 (Div. 2) 题解
Problem A: 题目大意: 给定两个数列\(a,b\),一次操作可以交换分别\(a,b\)数列中的任意一对数.求最少的交换次数使得任意一个数都在两个序列中出现相同的次数. (\(1 \leq a ...
- Codeforces Round #402 (Div. 2) 阵亡记
好长时间没有打Codeforces了,今天被ysf拉过去打了一场. lrd也来参(nian)加(ya)比(zhong)赛(sheng) Problem A: 我去,这不SB题吗.. 用桶统计一下每个数 ...
- CodeForces Round #402 (Div.2) A-E
2017.2.26 CF D2 402 这次状态还算能忍吧……一路不紧不慢切了前ABC(不紧不慢已经是在作死了),卡在D,然后跑去看E和F——卧槽怎么还有F,早知道前面做快点了…… F看了看,不会,弃 ...
- Codeforces Round #402 (Div. 2) B
Description Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10k. ...
随机推荐
- GIN+GORILLA=A GOLANG WEBSOCKET SERVER
鉴于聊天已然成为大部分app的基础功能,而大部分app用户基数有没有辣么大,常用的聊天server架构如xmpp或者消息队列实现之类的用起来还挺麻烦的,有比较难跟网页端做交互,加之H5标准落地,所以w ...
- vue路由总结
vue-router, vue自带的路由,下面是一些简单的操作说明: 一.安装 1.cnpm install vue-router --save 命令进行安装 2.在main.js或者使用vue-r ...
- adb pull / push
刚才搞了半天想pull,就是pull不成,如图: 看出哪里有问题了吗? 问题就是我不该在shell里面运行adb pull! 正确的做法: 在任意一处打开命令行比如图中的桌面, adb pull /s ...
- Swift扩展
Swift中的「扩展」(extensions)和OC中的categories类似,只是Swift中的「扩展」没有名字.Swift中的「扩展」可以向一个已有的类/结构体/枚举类型添加新功能,这包括在没有 ...
- POJ3273(最大化问题)
Monthly Expense Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 20603 Accepted: 8101 ...
- 配置android-studio应用的快捷键
http://blog.sina.com.cn/s/blog_ad64b8200102vnl4.html
- calicoctl命令简介
背景 在calico中,有多种网络资源.以v1.6.1为例,网络资源包含:node,bgpPeer,hostEndpoint,workloadEndpoint,ipPool,policy,profil ...
- 四、mysql数据常用命令
1.显示mysql中所有数据库的名称,show databases; 2.访问某个数据库,use database_name; 3.显示当前数据库中所有表的名称,show tables; 4.查看当前 ...
- Datawindow.net中实现让当前行选中,并且当前行以其他颜色显示
如何在Datawindow.net中实现让当前行选中,并且当前行以其他颜色显示 使用Datawindow.net要选中一行是很容易的意见事情,有很多种办法可以实现,最简单的莫过于使用selectrow ...
- sublime text3配置node.js环境,以及出现的问题
1) 下载sublime并安装,下载列表:https://www.sublimetext.com/3 2) 下载sublime的nodejs插件,需是集成Nodejs插件到sublime中,下载地址: ...