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 < ...
随机推荐
- Unbuntu18.04如何备份
以后可能用的到:https://blog.csdn.net/qq_35523593/article/details/78545530
- input类型
由于我们学习一个新的知识,而以前的都差不多忘完了,下面来复习我们以前学习的input的类型: button 点击的按钮 date 年/月/日 CheckBo ...
- 跟踪路由 tracert
由于最近遇到网络出现故障的问题,便使用到Tracert来确定了下出现故障的网络节点 记录下tracert命令相关内容 1. 简介 2. Tracert工作原理... 3. 常用参数 4. 使用示例与输 ...
- exp分析
1 from pwn import* 2 3 local =1 4 debug = 1 5 6 if local: 7 p = process('./pwn1') 8 else: 9 p = remo ...
- static 的三个作用
1).用于声明函数体内的变量为静态局部变量,存储在静态数据存储区,在函数被调用过程中维持其值保持不变 2).在文件内(函数体外)被声明为静态的变量,可以被文件内的所有函数访问,但不能被其他文件的函数访 ...
- Linux系统监视工具
转自 http://bbs.51cto.com/thread-971896-1.html # 1: top – 查看活动进程的命令TOP工具能够实时显示系统中各个进程的资源占用状况.默认情况 ...
- 学习boundingRectWithSize:options:attributes:context:计算文本尺寸
oundingRectWithSize:options:context: 返回文本绘制所占据的矩形空间. - (CGRect)boundingRectWithSize:(CGSize)size opt ...
- 了解CSS核心精髓(一)
CSS 1.css外联 正确写法:<link rel="stylesheet" href="css/style.css" /> <style ...
- javascript学习笔记 - 引用类型 Date
三 Date new Date() 在不传递参数的情况下,新创建的对象自动获得当前日期和时间.参数接收毫秒的timestamp Date.parse() 接收表示日期的字符串,返回相应的日期毫秒数ti ...
- 2016 年 ACM/ICPC 青岛区域赛 Problem C Pocky
昨晚乱入学弟的训练赛,想了一下这个题.推导的过程中,加深了对公理化的概率论理解.$\newcommand{\d}{\mathop{}\!\mathrm{d}}$ 解法一 考虑 $ d < L$ ...