CodeForces 779A Pupils Redistribution
简单题。
因为需要连边的人的个数一样,又要保证和一样,所以必须每个数字的个数都是一样的。
- #include<map>
- #include<set>
- #include<ctime>
- #include<cmath>
- #include<queue>
- #include<string>
- #include<vector>
- #include<cstdio>
- #include<cstring>
- #include<iostream>
- #include<algorithm>
- #include<functional>
- using namespace std;
- int a[],b[],n;
- int main()
- {
- scanf("%d",&n);
- for(int i=;i<=n;i++)
- {
- int x; scanf("%d",&x);
- a[x]++;
- }
- for(int i=;i<=n;i++)
- {
- int x; scanf("%d",&x);
- b[x]++;
- }
- int s1=,s2=;
- for(int i=;i<=;i++)
- {
- if(a[i]==b[i]) continue;
- if(abs(a[i]-b[i])%)
- {
- printf("-1\n");
- return ;
- }
- if(a[i]>b[i]) s1=s1+(a[i]-b[i])/;
- else s2=s2+(b[i]-a[i])/;
- }
- if(s1==s2) printf("%d\n",s1);
- else printf("-1\n");
- return ;
- }
CodeForces 779A Pupils Redistribution的更多相关文章
- 779A Pupils Redistribution
/* A. Pupils Redistribution time limit per test 1 second memory limit per test 256 megabytes input s ...
- 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个人的数目都变成一样的. 支持交换操作; 问你最少需要交换几次. [题解 ...
- 【推导】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]- ...
- CF779A(round 402 div.2 A) Pupils Redistribution
题意: In Berland each high school student is characterized by academic performance — integer value bet ...
- Codeforces #402
目录 Codeforces #402 Codeforces #402 Codeforces 779A Pupils Redistribution 链接:http://codeforces.com/co ...
- 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) 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 ...
随机推荐
- Eclipse srever起来时,时间超过45s。
双击servere的名字,在属性界面上进行修改. 如下图: 修改TimeOut中的值即可.
- SPOJ 104 HIGH - Highways
HIGH - Highways http://www.spoj.com/problems/HIGH/ In some countries building highways takes a lot o ...
- 【POJ】1222 EXTENDED LIGHTS OUT
[算法]高斯消元 [题解] 高斯消元经典题型:异或方程组 poj 1222 高斯消元详解 异或相当于相加后mod2 异或方程组就是把加减消元全部改为异或. 异或性质:00 11为假,01 10为真.与 ...
- JS之document例题讲解2
例题三.图片轮播 <body> <div style="width:1000px; height:250px; margin-top:30px"> < ...
- 【洛谷 T47488】 D:希望 (点分治)
题目链接 看到这种找树链的题目肯定是想到点分治的. 我码了一下午,\(debug\)一晚上,终于做到只有两个点TLE了. 我的是不完美做法 加上特判\(A\)了这题qwq 记录每个字母在母串中出现的所 ...
- React组件生命周期小结
React组件生命周期小结 下面所写的,只适合前端的React.(React也支持后端渲染,而且和前端有点小区别,不过我没用过.) 相关函数 简单地说,React Component通过其定义的几个函 ...
- 如何升级nodejs版本 安装n模块报错 npm ERR! notsup Unsupported platform
如何升级nodejs版本 首先安装n模块, 输入npm install -g n n模块专门用来管理nodejs的版本. 如果出现npm ERR! notsup Unsupported platfor ...
- JQGrid 导出Excel 获取筛选条件
需求描述:页面加载后,进行相关数据搜索,要求点击导出按钮后 下载Excel文件. 思路:希望在点击[导出Excel]按钮时,获取到表格搜索时的filters内容. 在百度.api.jqgrid.js ...
- input file 文件上传,js控制上传文件的大小和格式
文件上传一般是用jquery的uploadify,比较好用.后面会出文章介绍uploadify这个插件. 但是,有时候为了偷懒,直接就用input 的file进行文件和图片等的上传,input fil ...
- 开源网络准入系统(open source Network Access Control system)
开源网络准入系统(open source Network Access Control system) http://blog.csdn.net/achejq/article/details/5108 ...