CF779A(round 402 div.2 A) Pupils Redistribution
题意:
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 nstudents. 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
思路:
构造。
实现:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std; int n, tmp, ca[], cb[];
int main()
{
cin >> n;
for (int i = ; i < n; i++)
{
scanf("%d", &tmp);
ca[tmp]++;
}
for (int i = ; i < n; i++)
{
scanf("%d", &tmp);
cb[tmp]++;
}
int cnt = ;
bool flag = true;
for (int i = ; i <= ; i++)
{
tmp = abs(cb[i] - ca[i]);
if (tmp & )
{
flag = false;
break;
}
cnt += tmp;
}
if (!flag)
cout << "-1" << endl;
else
cout << cnt / + cnt % / << endl;
return ;
}
CF779A(round 402 div.2 A) Pupils Redistribution的更多相关文章
- 【推导】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 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)
Codeforces Round #402 (Div. 2) A. 日常沙比提 #include<iostream> #include<cstdio> #include< ...
- 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看了看,不会,弃 ...
- 【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) A
Description In Berland each high school student is characterized by academic performance — integer v ...
随机推荐
- react native camera
最近在尝试用react native camera iOS版本很方便就调试通过了,react的试用非常方便 android版本要单独试用fork的 屏蔽了lint的报错后也可以调试通过 参考这篇文章填 ...
- webpack与grunt/glub 的比较
webpack.grunt.glub 都是前端打包的工具: grunt/gulp 的工作方式是:在一个配置文件中,指明对某些文件进行压缩.组合.检查等任务的具体步骤,然后在运行中输入相应的命令. we ...
- DEDE内容页调用栏目的SEO标题、描述、关键字的方法
上篇写了<dedecms栏目页调用栏目关键词.描述的方法>,本章雨田SEOER讲述DEDE内容页调用栏目的SEO标题.描述.关键字的方法内容页调用SEO标题:在<title>& ...
- EOS智能合约为何选择Web Assembly(wasm)
比特币的程序非常简单,由解锁脚本和锁定脚本构成.以太坊有智能合约,有图灵完备的虚拟机EVM,但是指令也相对简单,且自成一套.这两种程序本质上都是脚本程序,即由程序翻译指令并执行,而不是由本地机器CPU ...
- mongodb c++ driver安装踩坑记
安装教程:https://mongodb.github.io/mongo-cxx-driver/mongocxx-v3/installation/ (1) “initializer_list” fil ...
- 自定义android 音乐通知栏 ——可伸缩扩展
Android custom notification for music player Example In this tutorial, you will learn how to creat ...
- 二维码解码器Zbar+VS2012开发环境配置
Zbar条码解码器是一个开源的二维码(包括条形码)解码器,可以识别来至于视频流,图像文件.手持扫码器和视频设备(如摄像头)等二维码识别,支持EAN-13/UPC-A, UPC-E, EAN-8, Co ...
- CodeForces979D:Kuro and GCD and XOR and SUM(Trie树&指针&Xor)
Kuro is currently playing an educational game about numbers. The game focuses on the greatest common ...
- 【USACO2017JAN】 Promotion Counting
[题目链接] 点击打开链接 [算法] 离散化 + dfs + 树状数组 [代码] #include<bits/stdc++.h> using namespace std; #define ...
- 廖雪峰ES6的箭头函数
http://www.liaoxuefeng.com/ wiki/001434446689867b27157e896e74d51a89c25cc8b43bdb3000/0014385659690576 ...