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看了看,不会,弃 ...
随机推荐
- 并发工具类(二)同步屏障CyclicBarrier
前言 JDK中为了处理线程之间的同步问题,除了提供锁机制之外,还提供了几个非常有用的并发工具类:CountDownLatch.CyclicBarrier.Semphore.Exchanger.Ph ...
- Python之模块(二)
1.subprocess模块 2.loggin模块 很多程序都有记录日志的需求,并且日志中包含的信息即有正常的程序访问日志,还可能有错误.警告等信息输出,python的logging模块提供了标准的日 ...
- python入门-IF语句
1 格式 cars = ['audi','bmw','subaru','toyata'] for car in cars: if car =='bmw': print(car.upper()) els ...
- 25. LiveBos调用class实例
var v= ABS_LOADBEAN('com.apex.mmsqljdbc.TestJDBC');var date=ABS_SQLVALUE("select to_char(?,'yyy ...
- leetcode944
public class Solution { public int MinDeletionSize(string[] A) { ; ; j < A[].Length; j++) { ; i & ...
- Mysql 索引优化 - 2
永远小表驱动大表(小数据驱动大数据) in exists区别, SELECT * FROM A WHERE A.id in (SELECT id FORM B) 若A表数据大于B表数据用in SELE ...
- 前端开发-2-HTML-head标签
browser英 /'braʊzə/ 美 /'braʊzɚ/ 浏览器 explorer英 /ek'splɔːrə(r)/ 美 /ɪk'splɔrɚ/ 探险者,资源管理器 1.index 2.head标 ...
- 2018.8.14-C#复习笔记总
using System; using System.Collections.Generic; //using System.Linq; using System.Text; using System ...
- Shiro权限总结
参考学习地址 shiro 瞅完就会用(ssm+shiro) Spring Shiro配置实现用户认证和授权 anon:它对应的过滤器里面是空的,什么都没做,另外.do和.jsp后面的*表示参 ...
- Haskell语言学习笔记(31)ListT
Control.Monad.Trans.List 标准库中的 ListT 的实现由于有 bug,已经被废弃. list-t 模块 这里使用 list-t 模块中的 ListT. list-t 模块需要 ...