HDU 5166 Missing number

来源:互联网 发布:投资软件 编辑:程序博客网 时间:2024/05/20 20:05

Missing number

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 78    Accepted Submission(s): 41


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. (T10)
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.(1n1,000)
 

Output
For each case output two numbers , small number first.
 

Sample Input
233 4 511
 

Sample Output
1 22 3
 

Source
BestCoder Round #28
 

Recommend
hujie   |   We have carefully selected several similar problems for you:  5169 5168 5167 5165 5164 
感觉这道题目题意难懂” In following a line , there are n distinct postive integers.(1n1,000)“这句话的意思是有n个不同的正整数,即有1个2个。。。1000个  但没有说明这些正整数的范围。。。

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<vector>
#include<cmath>
#include<stdlib.h>
#include<iomanip>
#include<list>
#include<deque>
#include<map>
#include <stdio.h>
#include <queue>
#include <stack>
#define maxn 10000+5
#define ull unsigned long long
#define ll long long
#define reP(i,n) for(i=1;i<=n;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define cle(a) memset(a,0,sizeof(a))
#define mod 90001
#define PI 3.141592657
#define INF 1<<30
const ull inf = 1LL << 61;
const double eps=1e-5;

using namespace std;

bool cmp(int a,int b){
return a>b;
};
int a[1004];
int b[2];
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int t,n,mark;
cin>>t;
while(t--)
{
mark=0;
cle(a);
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i];
sort(a+1,a+n+1);
cle(b);
int j=0;
for(int i=n-1;i>=1;i--)
{
if(a[i+1]-a[i]==3)
{
mark=1;cout<<a[i]+1<<" "<<a[i]+2<<endl;break;
}
if(a[i+1]-a[i]==2)
{
b[j++]=a[i]+1;
}
if(a[i+1]-a[i]==1)continue;
}
if(j==2)
{
cout<<b[1]<<" "<<b[0]<<endl;
}
else if(j==0&&!mark)
{
if(a[1]>2)cout<<a[1]-2<<" "<<a[1]-1<<endl;
else cout<<a[n]+1<<" "<<a[n]+2<<endl;
}
else if(j==1)
{
if(a[1]>1)cout<<a[1]-1<<" "<<b[0]<<endl;
else cout<<b[0]<<" "<<a[n]+1<<endl;
}
}
return 0;
}


标程的意思貌视是n个正整数,每个正整数的范围是1~1000..........不过当时是按照n个大小为整数范围内做的。。

按标程写的解法

#include <iostream>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <iomanip>
#include <list>
#include <deque>
#include <stack>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 1<<30
#define maxn 10000+10
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << 61;
const double eps=1e-5;
using namespace std;

bool cmp(int a,int b){
return a>b;
}
int a[1100];
int n;
int main()
{
#ifndef ONLINE_JUDGE
//freopen("in.txt","r",stdin);
#endif
//freopen("out.txt","w",stdout);
int t;
cin>>t;
while(t--){
cin>>n;
cle(a);
int b;
int Max=-1;
int Min=INF;
for(int i=1;i<=n;i++){
cin>>b;
a[b]++;
Max=max(b,Max);
Min=min(b,Min);
}
int num=0;
vector<int>v;
v.clear();
for(int i=Min;i<=Max;i++){
if(a[i]==0){
v.push_back(i);
num++;
}
}
if(num==2){
cout<<v[0]<<" "<<v[1]<<endl;
}
else if(num==1){
if(Min==1)cout<<v[0]<<" "<<Max+1<<endl;
else cout<<Min-1<<" "<<v[0]<<endl;
}
else if(num==0){
if(Min==1)cout<<Max+1<<" "<<Max+2<<endl;
else if(Min==2)cout<<1<<" "<<Max+1<<endl;
else cout<<Min-2<<" "<<Min-1<<endl;
}
}
return 0;
}



0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 中考作弊被捉了怎么办 露娜注册错了怎么办 去泰国开民宿怎么办工作签证 绩点2.7想出国怎么办 香港过境想去澳门怎么办 加拿大博士资格考试没通过怎么办 外国人没有学历怎么办工作签证 澳洲语言班挂了怎么办 英国学位翻译成文学硕士怎么办 没考上好的高中怎么办 毕业证12月发放申请英国怎么办 高二迷茫成绩差怎么办 高二期末考的差怎么办 法国留学签证办不下来怎么办 澳洲留学挂科签证续签怎么办 澳洲旅游签证被拒了怎么办 学校六级不让刷分怎么办 英国留学生怎么办申根签证 挂科太多拿不到学位证怎么办 ucl语言班没过怎么办 西澳大学工程挂科怎么办 澳洲语言班没过怎么办2018 杨浦区对口公立小学太差怎么办 公立小学太差了怎么办 澳大利亚出国留学怎么办-语言课程 学校不给释放信怎么办 重修费交不起钱怎么办 不想用家里的钱怎么办 三本学费太贵怎么办 从日本往中国汇款怎么办 学费钱大一没交怎么办 初中孩子和同学相处不好怎么办 使用假护照出国被发现怎么办 酒店忘记退房了怎么办 语言课申请不上怎么办 学会计的应届生想转行怎么办 上班熬不下去了怎么办 墨大选修挂科怎么办 日本签证年收入没有10w怎么办 做生意的办房贷没有薪资流水怎么办 澳洲医保卡丢了怎么办