Bestcoder BestCoder Round #28 A Missing number(查找缺失的合法数字)
For each test case , the first line contains a integers nn , which means the number of numbers the permutation has. In following a line ,
#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(查找缺失的合法数字)的更多相关文章
- Missing number - 寻找缺失的那个数字
需求:给出一个int型数组,包含不重复的数字0, 1, 2, ..., n:找出缺失的数字: 如果输入是[0, 1, 2] 返回 3 输入数组 nums = [0, 1, 2, 4] :应该返回 3 ...
- LeetCode 268. Missing Number (缺失的数字)
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missin ...
- 268. Missing Number序列中遗失的数字
[抄题]: Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is ...
- lintcode 中等题:find the missing number 寻找缺失的数
题目 寻找缺失的数 给出一个包含 0 .. N 中 N 个数的序列,找出0 .. N 中没有出现在序列中的那个数. 样例 N = 4 且序列为 [0, 1, 3] 时,缺失的数为2. 注意 可以改变序 ...
- Valid Number,判断是否为合法数字
问题描述: Validate if a given string is numeric. Some examples:"0" => true" 0.1 " ...
- [LeetCode] Missing Number 丢失的数字
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missin ...
- Missing number
Missing number 题目: Description There is a permutation without two numbers in it, and now you know wh ...
- [LeetCode] 268. Missing Number ☆(丢失的数字)
转载:http://www.cnblogs.com/grandyang/p/4756677.html Given an array containing n distinct numbers take ...
- Leetcode-268 Missing Number
#268. Missing Number Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find ...
随机推荐
- IDEA连接linux服务器
idea连接linux(完成了xshell和xftp连接linux的功能,可以直接卸载这俩了..) File->settings->Deployment左侧加号添加 选择传输类型ftp或者 ...
- MX
A mail exchanger record (MX record) is a type of resource record in the Domain Name System that spec ...
- 着陆攻击LAND Attack
着陆攻击LAND Attack 着陆攻击LAND Attack也是一种拒绝服务攻击DOS.LAND是Local Area Network Denial的缩写,意思是局域网拒绝服务攻击,翻译为着陆攻 ...
- 再次了解android中屏幕尺寸,单位等
android设备多种多样,要让你的app能够适配所有的屏幕是一件很痛苦的事情,在做适配之前我们首先需要了解android中dimension的定义 android中dimension是如何定义的? ...
- HDU 1045 Fire Net 状压暴力
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1045 Fire Net Time Limit: 2000/1000 MS (Java/Others) ...
- K&R——第五章 指针与数组
#include <stdio.h> #define maxsize 5000 char buf[maxsize]; char *head = buf; char *new(int siz ...
- electron入门教程
1.atom/electron github: https://github.com/atom/electron 中文文档: https://github.com/atom/electron/tree ...
- 邁向IT專家成功之路的三十則鐵律 鐵律二十二:IT人升遷之道-無為
升遷管道是許多人求職時相當重要的考量之一,畢竟人除了很愛錢之外更愛顯赫的頭銜,然而在企業中越顯赫的頭銜,其背後通常有更多的罵名,因為許多人的高官厚爵都是踩著一群人的頭頂爬上去的,隨時哪一天跌了下來,都 ...
- C++ 面试问题
一面 (1) 多态性都有哪些?(静态和动态,然后分别叙述了一下虚函数和函数重载) (2) 动态绑定怎么实现?(就是问了一下基类与派生类指针和引用的转换问题) (3) 类型转换有哪些?(四种类型转换,分 ...
- python 读取共享内存
测试环境 centos7 python3.6.5 首先使用c创建内存,这里的方法是:作为参数读一个二进制数据文件进去,把文件的内容作为共享内存的内容 定义块 #include <stdio.h& ...