写在前面的话:
博主现在读大一,对ACM竞赛有体验的想法,但是由于高中及高中之前阶段没有接触过NOIP所以博主的代码一向是比较简单,代码风格就像是小孩子,博主会尽力改善,近阶段可能是一些关于题目的一些总结概括,但是博主会尽力做好。
Problem Description
As we all know that, in an ACM contest, there is always an easy problem which every team can
AC it easily. We usually call this kind of problem, “the sign-in problem”.
But after the contest, we find that there is one team didn’t come to participate in the
contest, now please help me to find which team it is.
Input
The first line contains an integer T, meaning the number of the cases.
For each test case:
The first line is a number N (1 <= N <= 10^5) showing that N teams had registered for the contest. In the next line there are N distinct numbers, the team number of N teams. (The team number is an integer more than 0 and less than 10^8). The last line are N-1 distinct numbers, the team number of N-1 teams who AC the problem.
Output
“Team XXXXXXXX didn’t sign in!” (XXXXXXXX is the team number and should be 8 digits, using 0s to fill in if the number isn’t 8 digits).
Sample Input
2
2
10 30
10
3
1 2 3
1 3
Sample Output
Team 00000030 didn’t sign in!
Team 00000002 didn’t sign in!
题意大致是说要找出缺席的队伍的代码。
这个题也就算是很水了,这次我们考试的第一道题,表示好坑的输出格式啊。。。但是在这个里面我们可以发现比较两个相似的数组中不同元素的个数和位置时可以利用排序的方法来降低通过遍历搜索的时间复杂度,也就是说从O(n^2)变为O(n),如果题目数据范围小的话,可以利用数组本身的角标的性质去处理数组元素的有无。对了,我这里用的不是%08d,其实也可以用来处理数位,但是我觉得这样的话更好理解,而且我对08d并不是很熟。
下附代码
#include<stdio.h>
#include<string.h>
#include<queue>
#include<stack>
#include<stdlib.h>
#include<climits>
#include<iostream>
#include<algorithm>
using namespace std;
long long n;
int t;
long long arr[100003];
long long brr[100003];
int crr[100003];
int main()
{
cin>>t;
while(t--)
{
cin>>n;
int i=0,j=0;
long long ans;
memset(crr,0,sizeof(crr));
brr[n]=0;
for(i=1;i<=n;i++)
{
cin>>arr[i];
}
for(i=1;i<=n-1;i++)
{
cin>>brr[i];
}
sort(arr+1,arr+n+1);
sort(brr+1,brr+n+1);
for(i=1;i<=n;i++)
{
if(arr[i]!=brr[i])
{
ans = arr[i];
}
}
int b[9];
memset(b,0,sizeof(b));
for(i=1;i<9;i++)
{
b[i]=ans%10;
ans = ans / 10;
}
cout<<"Team ";
for(i=8;i>=1;i--)
{
cout<<b[i];
}
cout<<" didn't sign in!"<<endl;
}
return 0;
}