简单题。

因为需要连边的人的个数一样,又要保证和一样,所以必须每个数字的个数都是一样的。

  1. #include<map>
  2. #include<set>
  3. #include<ctime>
  4. #include<cmath>
  5. #include<queue>
  6. #include<string>
  7. #include<vector>
  8. #include<cstdio>
  9. #include<cstring>
  10. #include<iostream>
  11. #include<algorithm>
  12. #include<functional>
  13. using namespace std;
  14.  
  15. int a[],b[],n;
  16.  
  17. int main()
  18. {
  19. scanf("%d",&n);
  20. for(int i=;i<=n;i++)
  21. {
  22. int x; scanf("%d",&x);
  23. a[x]++;
  24. }
  25. for(int i=;i<=n;i++)
  26. {
  27. int x; scanf("%d",&x);
  28. b[x]++;
  29. }
  30.  
  31. int s1=,s2=;
  32.  
  33. for(int i=;i<=;i++)
  34. {
  35. if(a[i]==b[i]) continue;
  36. if(abs(a[i]-b[i])%)
  37. {
  38. printf("-1\n");
  39. return ;
  40. }
  41. if(a[i]>b[i]) s1=s1+(a[i]-b[i])/;
  42. else s2=s2+(b[i]-a[i])/;
  43. }
  44.  
  45. if(s1==s2) printf("%d\n",s1);
  46. else printf("-1\n");
  47.  
  48. return ;
  49. }

CodeForces 779A Pupils Redistribution的更多相关文章

  1. 779A Pupils Redistribution

    /* A. Pupils Redistribution time limit per test 1 second memory limit per test 256 megabytes input s ...

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

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

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

  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

    Codeforces Round #402 (Div. 2) A. Pupils Redistribution 模拟大法好.两个数列分别含有n个数x(1<=x<=5) .现在要求交换一些数 ...

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

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

随机推荐

  1. Eclipse srever起来时,时间超过45s。

    双击servere的名字,在属性界面上进行修改. 如下图: 修改TimeOut中的值即可.

  2. SPOJ 104 HIGH - Highways

    HIGH - Highways http://www.spoj.com/problems/HIGH/ In some countries building highways takes a lot o ...

  3. 【POJ】1222 EXTENDED LIGHTS OUT

    [算法]高斯消元 [题解] 高斯消元经典题型:异或方程组 poj 1222 高斯消元详解 异或相当于相加后mod2 异或方程组就是把加减消元全部改为异或. 异或性质:00 11为假,01 10为真.与 ...

  4. JS之document例题讲解2

    例题三.图片轮播 <body> <div style="width:1000px; height:250px; margin-top:30px"> < ...

  5. 【洛谷 T47488】 D:希望 (点分治)

    题目链接 看到这种找树链的题目肯定是想到点分治的. 我码了一下午,\(debug\)一晚上,终于做到只有两个点TLE了. 我的是不完美做法 加上特判\(A\)了这题qwq 记录每个字母在母串中出现的所 ...

  6. React组件生命周期小结

    React组件生命周期小结 下面所写的,只适合前端的React.(React也支持后端渲染,而且和前端有点小区别,不过我没用过.) 相关函数 简单地说,React Component通过其定义的几个函 ...

  7. 如何升级nodejs版本 安装n模块报错 npm ERR! notsup Unsupported platform

    如何升级nodejs版本 首先安装n模块, 输入npm install -g n n模块专门用来管理nodejs的版本. 如果出现npm ERR! notsup Unsupported platfor ...

  8. JQGrid 导出Excel 获取筛选条件

    需求描述:页面加载后,进行相关数据搜索,要求点击导出按钮后  下载Excel文件. 思路:希望在点击[导出Excel]按钮时,获取到表格搜索时的filters内容. 在百度.api.jqgrid.js ...

  9. input file 文件上传,js控制上传文件的大小和格式

    文件上传一般是用jquery的uploadify,比较好用.后面会出文章介绍uploadify这个插件. 但是,有时候为了偷懒,直接就用input 的file进行文件和图片等的上传,input fil ...

  10. 开源网络准入系统(open source Network Access Control system)

    开源网络准入系统(open source Network Access Control system) http://blog.csdn.net/achejq/article/details/5108 ...