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看了看,不会,弃 ...
随机推荐
- 对抗样本攻防战,清华大学TSAIL团队再获CAAD攻防赛第一
最近,在全球安全领域的殿堂级盛会 DEF CON 2018 上,GeekPwn 拉斯维加斯站举行了 CAAD CTF 邀请赛,六支由国内外顶级 AI 学者与研究院组成的队伍共同探讨以对抗训练为攻防手段 ...
- java基础:关于java流与文件操作
1.描述:流是字节数据或字符数据序列.Java采用输入流对象和输出流对象来支持程序对数据的输入和输出.输入流对象提供了数据从源点流向程序的管道,程序可以从输入流对象读取数据:输出流对象提供了数据从程序 ...
- django-插件django REST framework,返回序列化的数据
官网: http://www.django-rest-framework.org 1.安装 pip install djangorestframework 2.在setting.py中注册app 中添 ...
- python聚合云图
今天一时兴起,想用python爬爬自己的博客,通过数据聚合,制作高逼格的云图(对词汇出现频率视觉上的展示),看看最近我到底写了啥文章. 一.直接上几张我的博客数据的云图 1.1 爬取文章的标题的聚合 ...
- centos7.3使用squid搭建代理服务器
centos7.3使用squid搭建代理服务器 1 安装 yum install squid 2 编辑 vi /etc/squid/squid.conf 3 设置 最底部增加 如下http_acces ...
- 在Android中把内容写到XML文件中
在Android中把内容写到XML文件中 saveXmlButton.setOnClickListener(new OnClickListener() { @Override public void ...
- el 表达式的比较和包含
相等( equal ) :eq 不相等( not equal ): ne / neq 大于( greater than ): gt 小于( less than ): lt 大于等于( great th ...
- Android手机与服务器(案例一) webservice
1.服务端 建立webservice,增加方法gettime和sum. 测试正常8080端口,关闭防火墙. Start启动服务,并且OpenBrowser,XE6真是方便啊 http://localh ...
- 机器学习入门-使用GridSearch进行网格参数搜索GridSeach(RandomRegressor(), param_grid, cv=3)
1.GridSeach(RandomRegressor(), param_grid, cv=3) GridSearch第一个参数是算法本身, 第二个参数是传入的参数组合, cv表示的是交叉验证的次数 ...
- Spring Boot @Trasactionl 失效, JDK,CGLIB动态代理
来自: https://www.cnblogs.com/sweetchildomine/p/6978037.html?utm_source=itdadao&utm_medium=referra ...