B - A and B and Compilation Errors

本文讲述了A和B两位程序员在准备编程比赛时遇到的错误修复问题,以及他们在组建训练团队时如何优化成员分配以最大化知识分享的效果。在错误修复中,他们需要找出在两次编译后消失的两个错误。在团队构建中,A主张1个老手带2个新手,B则认为2个老手带1个新手更优。问题转化为在有限的老手和新手中,如何最大化团队数量。

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

A and B are preparing themselves for programming contests.

B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.

Initially, the compiler displayed n compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix some mistake and then another one mistake.

However, despite the fact that B is sure that he corrected the two errors, he can not understand exactly what compilation errors disappeared — the compiler of the language which B uses shows errors in the new order every time! B is sure that unlike many other programming languages, compilation errors for his programming language do not depend on each other, that is, if you correct one error, the set of other error does not change.

Can you help B find out exactly what two errors he corrected?

Input

The first line of the input contains integer n (3 ≤ n ≤ 105) — the initial number of compilation errors.

The second line contains n space-separated integersa1, a2, ..., an (1 ≤ ai ≤ 109) — the errors the compiler displayed for the first time.

The third line contains n - 1 space-separated integersb1, b2, ..., bn - 1 — the errors displayed at the second compilation. It is guaranteed that the sequence in the third line contains all numbers of the second string except for exactly one.

The fourth line contains n - 2 space-separated integersс1, с2, ..., сn - 2 — the errors displayed at the third compilation. It is guaranteed that the sequence in the fourth line contains all numbers of the third line except for exactly one.

Output

Print two numbers on a single line: the numbers of the compilation errors that disappeared after B made the first and the second correction, respectively.

Sample test(s)
Input
5
1 5 8 123 7
123 7 5 1
5 1 7
Output
8
123
Input
6
1 4 3 3 5 7
3 7 5 4 3
4 3 7 5
Output
1
3

 

题目的大意是:
给你三组数据,要你每次判断出比上一次减少了哪个数。有两种方法,虽说是水题,但是也能学到点什么的。
方法一:
#include<stdio.h>
#include<string.h>
int a[100001],b[100001],c[100001];
int main(){
	int n,i,j,k;
	int sum1,sum2;
	memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); memset(c,0,sizeof(c));
	scanf("%d",&n);
	for(i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(i=1;i<n;i++)
		scanf("%d",&b[i]);
	for(i=1;i<=n-2;i++)
		scanf("%d",&c[i]);
	sum1=sum2=0;
	#if 1
	for(i=1;i<=n;i++){
		sum1+=a[i];
		sum1-=b[i];
		//printf("%d\n",sum1);
	}
	#endif
	#if 1
	for(i=1;i<=n-1;i++){
		sum2+=b[i];
		sum2-=c[i];
	}
	#endif
	printf("%d\n%d\n",sum1,sum2);
}

//第一种方法,就是加一次第一组的数然后再减掉第二组的数,最后求得的sum1就是第二组缺少的数。同理也可得sum2就是第三组比第二组少的数。
最后输出来就可以了。
 
#include<stdio.h>
#include<algorithm>
#include<iostream>
using namespace std;

int main()
{
	int n;
	int a[100010],b[100010],c[100010];
	while(scanf("%d", &n)!=EOF)
	{
	int i;
		for(i=0;i<n;i++) scanf("%d", &a[i]);
		for(i=0;i<n-1;i++) scanf("%d", &b[i]);
		for(i=0;i<n-2;i++) scanf("%d", &c[i]);
    	sort(a,a+n);
    	sort(b,b+n-1);
    	sort(c,c+n-2);
    	int p=0,l=0;
		for(i=0;i<n-1;i++)
		{	p++;
			if(a[i]!=b[i]) 
			{
				printf("%d\n",a[i]);
				break;
			}
		}
		if(p==i) printf("%d\n",a[p]); 
	
		for(i=0;i<n-1;i++)
		{   	l++;
			if(b[i]!=c[i]) 
			{
				printf("%d\n",b[i]);
				break;
			}
		}
		if(l==i) printf("%d\n",b[l]); 
	}
}

//第二种方法:
就是每次对每组排序,然后如果 a[i]!=b[i]的话,那么就输出a[i],如果全部循环完了,但是还是没发现这种情况,那么就输出最后一个数字a[p];
同理对第三组也是这样。
 
 
C - A and B and Team Training
Crawling in process...Crawling failedTime Limit:1000MS    Memory Limit:262144KB    64bit IO Format:%I64d & %I64u

A and B are preparing themselves for programming contests.

An important part of preparing for a competition is sharing programming knowledge from the experienced members to those who are just beginning to deal with the contests. Therefore, during the next team training A decided to make teams so that newbies are solving problems together with experienced participants.

A believes that the optimal team of three people should consist of one experienced participant and two newbies. Thus, each experienced participant can share the experience with a large number of people.

However, B believes that the optimal team should have two experienced members plus one newbie. Thus, each newbie can gain more knowledge and experience.

As a result, A and B have decided that all the teams during the training session should belong to one of the two types described above. Furthermore, they agree that the total number of teams should be as much as possible.

There are n experienced members and m newbies on the training session. Can you calculate what maximum number of teams can be formed?

Input

The first line contains two integers n and m (0 ≤ n, m ≤ 5·105) — the number of experienced participants and newbies that are present at the training session.

Output

Print the maximum number of teams that can be formed.

Sample test(s)
Input
2 6
Output
2
Input
4 5
Output
3

 

题目的大致意思就是给你两种选队员的方案,一种是选2个新队员1个老队员,第二种是选1个新队员2个老队员。问怎样选择才能使得队伍的数量最大。

实际上就是一个模拟:

#include<stdio.h>
#include<string.h>
int main(){
	int n,m,i,j,k,num=0;
	scanf("%d%d",&n,&m);
	int old,new1;
	old=n; new1=m;
	while(1){
		while(old<=new1&&old>=1&&new1>=2){
			old--;
			new1=new1-2;
			num++;
		}
		while(new1<=old&&new1>=1&&old>=2){
			new1--;
			old=old-2;
			num++;
		}
		if(new1<=0 || old<=0 ||(new1==1&&old==1))  break;
	}
	printf("%d\n",num);
}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值