CodeForces 779A Pupils Redistribution

本文解析了一道简单的编程题目,通过对输入的两组数据进行对比,判断是否可以通过特定操作使得两组数据相同。主要涉及数组处理及计数比较等内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

简单题。

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

#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;
}

 

转载于:https://www.cnblogs.com/zufezzt/p/6539121.html

期末作业要求如下: Write a program that will help elementary school pupils practice math. a) The program will first ask the user for his/her ID number (including two letters & 4 digits), e.g. Please input your four digit ID no: AB1234 The program should have input validation. Then the program prompts three choices: (1) Start a test (2) Check scores (3) Exit Test: the program will give 10 math problems, e.g.: 12 * 3 = 36 48 + 32 = 80 … 56 / 28 = 2 Note: i) Pupils will answer each problem before the next one is given. ii) The problems should include addition, subtraction, multiplication and division. They are randomly generated. iii) Randomly generates numbers for problems. However, must ensure that both the problem and the result are no larger than two digits. The problem and the result should be greater than or equal to zero. The divisor cannot be zero. iv) After ten problems are finished, record the time used by the student to do the ten problems. v) Gives a score to each student. Saves this student’s ID, his/her score and the time used into a file named ‘record.txt’. vi) Print the following information on the screen: Prob. | Correct Answ. | Ur Answ c) Check scores: Searches the file ‘record.txt’ and lists all the historical scores for this student, e.g.: Your previous records are: AB1234 80 150 seconds AB1234 50 182 seconds AB1234 90 98 seconds You will be marked based on your program’s: (1) Correctiveness (2) Readability (3) Robustness (4) Conciseness 目前本人的程序可以直接使用,并完全满足要求。还是建议学弟学妹在字里行间多多理解,争取自己写出漂亮的代码! 向本人在完成此作业过程中参考的代码表示衷心的感谢!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值