水题,开始没读懂题意,以为17 18 19,少的两个数字是15 16,结果应该是1,2;
从1—n+2个数之间查找即可,我还给排了序;这题一看有好多种做法,标记也可以用结构体,脑子里有好几种思路,第一种思路卡的时候就切换到第二种思路,结果脑子就乱了,其实刚开始想想的话就可以马上做出来!
题意:输入t组数据,每组m个数,输入m个数,从1—m+2之间,从小到大,输出缺少的2个数。
Missing number
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 255 Accepted Submission(s): 137
Problem Description
There is a permutation without two numbers in it, and now you know what numbers the permutation has. Please find the two numbers it lose.
Input
There is a number
T
shows there are
T
test cases below. (
T≤10
)
For each test case , the first line contains a integers n , which means the number of numbers the permutation has. In following a line , there are n distinct postive integers.( 1≤n≤1,000 )
For each test case , the first line contains a integers n , which means the number of numbers the permutation has. In following a line , there are n distinct postive integers.( 1≤n≤1,000 )
Output
For each case output two numbers , small number first.
Sample Input
2 3 3 4 5 1 1
Sample Output
1 2 2 3
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
int t,n,a[1010],b[1010];
while(scanf("%d",&t)!=EOF)
{
while(t--)
{
scanf("%d",&n);
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
for(int i=1;i<=1000;i++)
b[i]=i;
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
b[a[i]]=-1;
}
sort(a,a+n);
int f=1;
for(int i=1;i<=n+2;i++)
{
if(b[i]!=-1&&f==2)
{
printf("%d\n",i);
f++;
break;
}
if(b[i]!=-1&&f<2)
{
printf("%d ",i);
f++;
}
}
}
}
return 0;
}