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?
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.
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.
5 1 5 8 123 7 123 7 5 1 5 1 7
8 123
6 1 4 3 3 5 7 3 7 5 4 3 4 3 7 5
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 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?
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.
Print the maximum number of teams that can be formed.
2 6
2
4 5
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);
}