AC日记——Pupils Redistribution Codeforces 779a
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
思路:
模拟;
来,上代码:
#include <cmath>
#include <cstdio>
#include <iostream>
#include <algorithm> using namespace std; int if_z,n,ai[],bi[],vi[]; char Cget; inline void in(int &now)
{
now=,if_z=,Cget=getchar();
while(Cget>''||Cget<'')
{
if(Cget=='-') if_z=-;
Cget=getchar();
}
while(Cget>=''&&Cget<='')
{
now=now*+Cget-'';
Cget=getchar();
}
now*=if_z;
} int main()
{
in(n);int pos,cur=,kol=;
for(int i=;i<=n;i++) in(pos),ai[pos]++;
for(int i=;i<=n;i++) in(pos),bi[pos]++;
for(int i=;i<=;i++)
{
vi[i]=ai[i]-bi[i];
vi[i]/=,cur+=vi[i];
if(vi[i]>) kol+=vi[i];
pos=abs(ai[i]-bi[i]);
if(pos%)
{
cout<<"-1";
return ;
}
}
if(cur==) cout<<kol;
else cout<<"-1";
return ;
}
AC日记——Pupils Redistribution Codeforces 779a的更多相关文章
- AC日记——Cards Sorting codeforces 830B
Cards Sorting 思路: 线段树: 代码: #include <cstdio> #include <cstring> #include <iostream> ...
- AC日记——Card Game codeforces 808f
F - Card Game 思路: 题意: 有n张卡片,每张卡片三个值,pi,ci,li: 要求选出几张卡片使得pi之和大于等于给定值: 同时,任意两两ci之和不得为素数: 求选出的li的最小值,如果 ...
- AC日记——Success Rate codeforces 807c
Success Rate 思路: 水题: 代码: #include <cstdio> #include <cstring> #include <iostream> ...
- AC日记——T-Shirt Hunt codeforces 807b
T-Shirt Hunt 思路: 水题: 代码: #include <cstdio> #include <cstring> #include <iostream> ...
- AC日记——Magazine Ad codeforces 803d
803D - Magazine Ad 思路: 二分答案+贪心: 代码: #include <cstdio> #include <cstring> #include <io ...
- AC日记——Broken BST codeforces 797d
D - Broken BST 思路: 二叉搜索树: 它时间很优是因为每次都能把区间缩减为原来的一半: 所以,我们每次都缩减权值区间. 然后判断dis[now]是否在区间中: 代码: #include ...
- AC日记——Array Queries codeforces 797e
797E - Array Queries 思路: 分段处理: 当k小于根号n时记忆化搜索: 否则暴力: 来,上代码: #include <cmath> #include <cstdi ...
- AC日记——Maximal GCD codeforces 803c
803C - Maximal GCD 思路: 最大的公约数是n的因数: 然后看范围k<=10^10; 单是答案都会超时: 但是,仔细读题会发现,n必须不小于k*(k+1)/2: 所以,当k不小于 ...
- AC日记——Vicious Keyboard codeforces 801a
801A - Vicious Keyboard 思路: 水题: 来,上代码: #include <cstdio> #include <cstring> #include < ...
随机推荐
- uvm transaction modeling
1.what is transaction? network transactions tcp/ip wifi 3g/4g bus transactions amba-ahb/apb/axi pci/ ...
- 【mysql】[Err]1267 - Illegal mix of collations(utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLICIT) for operation ‘=
ALTER TABLE table_name CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
- 【mac】【nginx】开机重启
homebrew.mxcl.nginx.plist <?xml version="1.0" encoding="UTF-8"?> <!DOCT ...
- 阿里云全国快递物流查询api接口
口地址: https://market.aliyun.com/products/56928004/cmapi021863.html?spm=5176.730005.productlist.d_cmap ...
- 收集的有关mdk 3的使用方法
收集来自网络上的有关mdk3的一些使用方法以及技巧(持续更新) b beacon泛洪攻击 -f 指定wifi名称的文件夹 -n 加上wifi名称 -w Fake WEP encrypted sta ...
- 【草稿】JS中如何操作时间
如何声明时间变量 如何设置时间变量的时.分.秒.毫秒 如何根据字符串变量,声明指定的时间变量 如何比较两个时间变量 代码如下: $(function () { var d = new Date(); ...
- golang导出excel(excel格式)
之前写过一篇导出cvs格式的,如果只是简单导出完全能满足需要.按时如果想要有复杂需求,如样式定制.多个sheet之类的,就无法完成了.之后发现有人已经实现golang直接excel对excel的操作, ...
- c++ dll 创建
建立一个C++的Win32DLL,这里要注意选择"Export symbols"导出符号.点击完成. 如下图所示: 由于项目的名称是"TestCPPDLL" ...
- luogu1578 奶牛浴场 枚举点最大子矩阵
建议看看王知昆dalao的论文,讲得很好 #include <algorithm> #include <iostream> #include <cstring> # ...
- 基于JQuery的WEB套打设计器jatoolsPrinter1.0
开发web套打应用时,如快递单打印,一般要经过以下步骤:1. 扫描快递单据,保存成一个图片文件2. 将底图作成<img>3. 在<img>上放置打印项,试着打印到打印机,观察有 ...