/*

A. Pupils Redistribution
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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.

Output

Print the required minimum number of exchanges or -1, if the desired distribution of students can not be obtained.

Examples
Input
4
5 4 4 4
5 5 4 5
Output
1
Input
6
1 1 1 1 1 1
5 5 5 5 5 5
Output
3
Input
1
5
3
Output
-1
Input
9
3 2 5 5 2 3 3 3 2
4 1 4 1 1 2 4 4 1
Output
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的更多相关文章

  1. CodeForces 779A Pupils Redistribution

    简单题. 因为需要连边的人的个数一样,又要保证和一样,所以必须每个数字的个数都是一样的. #include<map> #include<set> #include<cti ...

  2. AC日记——Pupils Redistribution Codeforces 779a

    A. Pupils Redistribution time limit per test 1 second memory limit per test 256 megabytes input stan ...

  3. 【codeforces 779A】Pupils Redistribution

    [题目链接]:http://codeforces.com/contest/779/problem/A [题意] 让你把两个组的5个人的数目都变成一样的. 支持交换操作; 问你最少需要交换几次. [题解 ...

  4. CF779A(round 402 div.2 A) Pupils Redistribution

    题意: In Berland each high school student is characterized by academic performance — integer value bet ...

  5. 【推导】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]- ...

  6. Codeforces #402

    目录 Codeforces #402 Codeforces #402 Codeforces 779A Pupils Redistribution 链接:http://codeforces.com/co ...

  7. 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 ...

  8. 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 ...

  9. CodeForces Round #402 (Div.2) A-E

    2017.2.26 CF D2 402 这次状态还算能忍吧……一路不紧不慢切了前ABC(不紧不慢已经是在作死了),卡在D,然后跑去看E和F——卧槽怎么还有F,早知道前面做快点了…… F看了看,不会,弃 ...

随机推荐

  1. 并发基础(七) Thread 类的sleep()、yeild()、join()

    1.Thread.sleep(long millis ) sleep( )是一个静态方法,让当前正在执行的线程休眠(暂停执行),而且在睡眠的过程是不释放资源的,保持着锁. 在睡眠的过程,可以被中断,注 ...

  2. php使用tcpdf实现在线PDF功能

    今天看书,发现有个例子就是实现php生成pdf格式文件的例子,所以扩展了下百度了下 找了个tcpdf Git上有地址,如果感冒自行下载 https://github.com/tecnickcom/tc ...

  3. quartz 的简单使用

    0.依赖: <!-- 引入quartz对应的依赖 --> <dependency> <groupId>org.quartz-scheduler</groupI ...

  4. mysql的时区错误的解决办法

    十二月 02, 2018 9:16:19 下午 com.mchange.v2.resourcepool.BasicResourcePool 警告: Having failed to acquire a ...

  5. ABAP-关于隐式与显式的DB Commit

    转载:https://www.cnblogs.com/liaojunbo/archive/2011/07/11/2103491.html 1.显式的DB Commit 显式的DB Commit并没有对 ...

  6. keepalive配置与管理

    什么是Keepalived呢,keepalived观其名可知,保持存活,在网络里面就是保持在线了,也就是所谓的高可用或热备,用来防止单点故障(单点故障是指一旦某一点出现故障就会导致整个系统架构的不可用 ...

  7. KKT条件的物理意义(转)

    最好的解释:https://www.quora.com/What-is-an-intuitive-explanation-of-the-KKT-conditions# 作者:卢健龙链接:https:/ ...

  8. 首届阿里巴巴在线技术峰会,9位大V演讲整理!

    https://yq.aliyun.com/articles/57826 感谢参加阿里巴巴在线技术峰会.7月19日的3场专家分享:Blink.Docker.电商互动:7月20日的云数据库十大经典案 例 ...

  9. Eclipse中spring项目的XML文件的问题

    XML文件提示Start state definition is missing. Add a 'start-state' element 原因:Eclipse 认为 XML 是“Spring Web ...

  10. go 格式化时间戳

    func main() { //获取时间戳 timestamp := time.Now().Unix() fmt.Println(timestamp) //格式化为字符串,tm为Time类型 tm : ...