779A Pupils Redistribution
/*
1 second
256 megabytes
standard input
standard output
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 <iostream>
#include <bits/stdc++.h>
using namespace std;
int a[], b[];
int x[], y[];
int main()
{
int n;
cin >> n;
for(int i = ; i < n; i++)
{
cin >> a[i];
x[a[i]] ++;
}
for(int i = ; i < n; i++)
{
cin >> b[i];
y[b[i]] ++;
}
for(int i = ; i <= ; i++)
{
if((x[i] + y[i]) % != )
{
cout << "-1" << endl;
return ;
}
}
int aim = ;
for(int i = ; i <= ; i++)
{
aim += abs(x[i] - y[i]) / ;
}
cout << aim / << endl;
return ;
}
779A Pupils Redistribution的更多相关文章
- CodeForces 779A Pupils Redistribution
简单题. 因为需要连边的人的个数一样,又要保证和一样,所以必须每个数字的个数都是一样的. #include<map> #include<set> #include<cti ...
- AC日记——Pupils Redistribution Codeforces 779a
A. Pupils Redistribution time limit per test 1 second memory limit per test 256 megabytes input stan ...
- 【codeforces 779A】Pupils Redistribution
[题目链接]:http://codeforces.com/contest/779/problem/A [题意] 让你把两个组的5个人的数目都变成一样的. 支持交换操作; 问你最少需要交换几次. [题解 ...
- CF779A(round 402 div.2 A) Pupils Redistribution
题意: In Berland each high school student is characterized by academic performance — integer value bet ...
- 【推导】Codeforces Round #402 (Div. 2) A. Pupils Redistribution
一次交换,会让Group A里面的某个数字的数量-1,另一个数字的数量+1:对Group B恰好相反. 于是答案就是xigma(i=1~5,numA[i]-numB[i]>0)(numA[i]- ...
- Codeforces #402
目录 Codeforces #402 Codeforces #402 Codeforces 779A Pupils Redistribution 链接:http://codeforces.com/co ...
- 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) A B C sort D二分 (水)
A. Pupils Redistribution time limit per test 1 second memory limit per test 256 megabytes input stan ...
- CodeForces Round #402 (Div.2) A-E
2017.2.26 CF D2 402 这次状态还算能忍吧……一路不紧不慢切了前ABC(不紧不慢已经是在作死了),卡在D,然后跑去看E和F——卧槽怎么还有F,早知道前面做快点了…… F看了看,不会,弃 ...
随机推荐
- ajax 方法的使用以及方法中各参数的含义
由于近来经常在项目中使用 ajax 这个函数,在工作之余自己查找了相关的资料,并总结了 ajax 方法的使用,以及方法中各个参数的含义,供大家学习参考使用 type: 要求为String类型的参数,请 ...
- mac mysql中文乱码问题
God,今天看了好多资料,除了让我命令更熟练以外浪费了好多时间. 遇到的问题:写入数据库有中文的时候,显示??? 最后解决办法: 1.打开终端,输入: mysql -u root -p,然后输入mys ...
- 过滤器 ;spring拦截器 切片 小结
1. springMVc的拦截器 实现HandlerInterceptor接口,如下: public class HandlerInterceptor1 implements HandlerInter ...
- SQL SERVER2008 DBX Error: Driver could not be properly initialized
raised exception class TDBXError with message 'DBX Error: Driver could not be properly initialized. ...
- J2SE 8的输入输出--读取/写入文本文件和读取/写入二进制数据
读取/写入文本文件 // 1. 文本输入 // (1) 短小文本直接转入字符串 String string = new String(Files.readAllBytes(Paths.get(&quo ...
- Maven 多环境 打包
1.pom.xml文件添加profiles属性 <profiles> <profile> <id>dev</id> <activation> ...
- air 桌面应用发布后可以删除的文件
****\Adobe AIR\Versions\1.0 下的文件夹Resources,可以整个删除 ***META-INF\AIR目录下的application.xml配置文件可修改initialWi ...
- AMD 与CMD
AMD AMD是"Asynchronous Module Definition"的缩写,意思就是"异步模块定义".它采用异步方式加载模块,模块的加载不影响它后面 ...
- Linux逻辑卷的拉伸和缩小
相对于普通磁盘优势是逻辑卷可以在线动态的拉伸(不用先unmount操作),只要vg中有足够的空间即可 1:首先查看vg是否有足够的空间 [root@gechong mapper]# vgdisplay ...
- ubuntu ftp 建立匿名用户 [转]
转自:http://www.cnblogs.com/cocoajin/p/3761414.html ubuntu server vsftpd 匿名用户上传下载及目录设置 1:vsftpd服务器安装: ...