简单题。

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

#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的更多相关文章

  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. 洛谷2115 [USACO14MAR]破坏Sabotage

    https://www.luogu.org/problem/show?pid=2115 题目描述 Farmer John's arch-nemesis, Farmer Paul, has decide ...

  2. 【C++ STL】List

    1.结构 list使用一个double linked list(双向链表)来管理元素. 2. list 能力 list内部结构和vector或deque截然不同,所以与他们的区别: list不支持随机 ...

  3. PHP扩展--Yaf框架安装

    安装/配置 编译安装 wge thttp://pecl.php.net/get/yaf-2.3.5.tgz tar -zxvfyaf-2.3.5.tgz cd yaf-2.3.5/ cd extens ...

  4. 元类编程-- metaclass

    #类也是对象,type创建类的类 def create_class(name): if name == "user": class User: def __str__(self): ...

  5. JDBC和Ibatis中的Date,Time,Timestamp处理

    在此前,遇到过使用Ibatis操作Oracle时时间精度丢失的问题,昨天又遇到JDBC操作MySQL时间字段的问题,从网上看到各种式样的解释这些问题的博文/帖子,但多是雾里看花,不得要领. 理解JDB ...

  6. Centos修改镜像为国内的阿里云源或者163源等国内源

    阿里安装软件镜像源 阿里云Linux安装镜像源地址:http://mirrors.aliyun.com/ 第一步:备份你的原镜像文件,以免出错后可以恢复. mv /etc/yum.repos.d/Ce ...

  7. python进行机器学习(五)之模型打分

    一.画出模型的残差值分布情况 #!/usr/bin/python import pandas as pd import numpy as np import csv as csv import mat ...

  8. Arduino 舵机sg90电位器实现转动方向控制

    /* Sweep*/ #include <Servo.h> int potpin = 0;//电位器接到A0 int val; //存储电位器读取的数值 Servo myservo//定义 ...

  9. Part2-HttpClient官方教程-Chapter5-流利的API

    5.1. 易于使用的Facade API 使用之前注意引入相应Jar包或者Maven依赖 <dependency> <groupId>org.apache.httpcompon ...

  10. 基于ansj_seg和nlp-lang的简单nlp工具类

    1.首先在pom中引入ansj_seg和nlp-lang的依赖包, ansj_seg包的作用: 这是一个基于n-Gram+CRF+HMM的中文分词的java实现: 分词速度达到每秒钟大约200万字左右 ...