首页 > 代码库 > CodeForces 779A Pupils Redistribution

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[110],b[110],n;int main(){    scanf("%d",&n);    for(int i=1;i<=n;i++)    {        int x; scanf("%d",&x);        a[x]++;    }    for(int i=1;i<=n;i++)    {        int x; scanf("%d",&x);        b[x]++;    }    int s1=0,s2=0;    for(int i=1;i<=5;i++)    {        if(a[i]==b[i]) continue;        if(abs(a[i]-b[i])%2)        {            printf("-1\n");            return 0;        }        if(a[i]>b[i]) s1=s1+(a[i]-b[i])/2;        else s2=s2+(b[i]-a[i])/2;    }    if(s1==s2) printf("%d\n",s1);    else printf("-1\n");    return 0;}

 

CodeForces 779A Pupils Redistribution