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<=10T≤10)
For each test case , the first line contains a integers  nn , which means the number of numbers the permutation has. In following a line ,
there are  nnN distinct postive integers.(1<=n<=10001≤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
Source
 
代码:

 #include <stdio.h>
#include <string.h>
#include <math.h>
#include <queue>
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define FOR_e(i, a, b) for(int i=a; i<=b; i++) using namespace std;
int f[];
int main()
{
int t, dd;
int ma, mi;
scanf("%d", &t);
int i, n;
while(t--)
{
scanf("%d", &n);
memset(f, , sizeof(f));
ma=-; mi=;
for(i=; i<n; i++)
{
scanf("%d", &dd);
f[dd]=;
if(dd>ma) ma=dd;
if(dd<mi) mi=dd;
}
queue<int>q;
while(!q.empty()) q.pop();
for(i=mi; i<=ma; i++)
if(f[i]==)
{
//printf("%d--", i);
q.push(i);
}
if(q.size()>=)
{
dd=q.front(); q.pop(); printf("%d ", dd);
dd=q.front(); q.pop(); printf("%d\n", dd);
}
else if(q.size()==)
{
dd=q.front(); q.pop(); printf("%d ", dd);
if(mi==)
{
printf("%d\n", ma+);
}
else if(mi>)
{
printf("%d\n", mi-);
}
}
else if(q.size()==)
{
if(mi>)
{
printf("%d %d\n", mi-, mi-);
}
else if(mi==)
{
printf("%d %d\n", mi-, ma+);
}
else
{
printf("%d %d\n", ma+, ma+);
}
}
}
return ;
}

Bestcoder BestCoder Round #28 A Missing number(查找缺失的合法数字)的更多相关文章

  1. Missing number - 寻找缺失的那个数字

    需求:给出一个int型数组,包含不重复的数字0, 1, 2, ..., n:找出缺失的数字: 如果输入是[0, 1, 2] 返回 3 输入数组 nums = [0, 1, 2, 4] :应该返回 3 ...

  2. LeetCode 268. Missing Number (缺失的数字)

    Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missin ...

  3. 268. Missing Number序列中遗失的数字

    [抄题]: Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is ...

  4. lintcode 中等题:find the missing number 寻找缺失的数

    题目 寻找缺失的数 给出一个包含 0 .. N 中 N 个数的序列,找出0 .. N 中没有出现在序列中的那个数. 样例 N = 4 且序列为 [0, 1, 3] 时,缺失的数为2. 注意 可以改变序 ...

  5. Valid Number,判断是否为合法数字

    问题描述: Validate if a given string is numeric. Some examples:"0" => true" 0.1 " ...

  6. [LeetCode] Missing Number 丢失的数字

    Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missin ...

  7. Missing number

    Missing number 题目: Description There is a permutation without two numbers in it, and now you know wh ...

  8. [LeetCode] 268. Missing Number ☆(丢失的数字)

    转载:http://www.cnblogs.com/grandyang/p/4756677.html Given an array containing n distinct numbers take ...

  9. Leetcode-268 Missing Number

    #268.  Missing Number Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find ...

随机推荐

  1. GitHub 上受欢迎的 Android UI Library 整理(一)

    抽屉菜单 https://github.com/mikepenz/MaterialDrawer ★7337 - 安卓抽屉效果实现方案https://github.com/Yalantis/Side-M ...

  2. jenkins+gitlab发布maven项目

    1.简介:什么是Maven Maven是一个项目管理和综合工具.Maven提供给开发人员构建一个完整的生命周期框架; 开发团队可以自动完成该项目的基础设施建设,Maven使用标准的目录结构和默认构建生 ...

  3. [Bzoj4943][Noi2017]蚯蚓(hash)

    4943: [Noi2017]蚯蚓 Time Limit: 50 Sec  Memory Limit: 512 MBSubmit: 237  Solved: 110[Submit][Status][D ...

  4. Java实验--关于课上找“水王”问题分析

    问题的表述就是说有那么一个人,他在一个论坛上发帖,然后每贴必回,自己也发帖.那么这个人在发帖的数目上就超过了整个论坛的帖子数目的一半以上. 我对这个问题一开始的思路是,用SQL语句获取整个列表中的数据 ...

  5. sql标准支持了事务隔离级别

    事务隔离级别 尽管数据库为用户提供了锁的DML操作方式,但直接使用锁管理是非常麻烦的,因此数据库为用户提供了自动锁机制.只要用户指定会话的事务隔离级别,数据库就会分析事务中的SQL语句,然后自动为事务 ...

  6. filter 中用spring StopWatch 监控请求执行时间

    在filter中用spring stopWatch 来统计每个请求的执行时间: 虽然在firefox 中可以清楚的看到每个请求的执行时间,但是为了测试,记录日志, 方便以后查询维护. 还是必要的,下面 ...

  7. C#规范整理·集合和Linq

    LINQ(Language Integrated Query,语言集成查询)提供了类似于SQL的语法,能对集合进行遍历.筛选和投影.一旦掌握了LINQ,你就会发现在开发中再也离不开它.   开始! 前 ...

  8. Java Unsafe类

    参考了这篇文章:http://blog.csdn.net/aesop_wubo/article/details/7537278 <JAVA并发编程学习笔记之Unsafe类> Unsafe开 ...

  9. HDU1532_Drainage Ditches(网络流/EK模板/Dinic模板(邻接矩阵/前向星))

    Drainage Ditches Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  10. loarocks install loadcaffe 失败

    loarocks install loadcaffe 失败 1.Error: Your user does not have write permissions in /home/zhangliang ...