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 ...
随机推荐
- CF768
Codeforces Round #406 (Div. 1) A.Berzerk 考虑先手必胜态,一定是先手移动到某一个位置以后,这个位置是后手的必败态 考虑先手必败态,一定是无论先手如何移动,先手所 ...
- ajax跨域-springboot
package com.xxxx.xx.service.configuration; import org.springframework.context.annotation.Bean; impor ...
- BZOJ1003物流運輸 DP + SPFA
@[DP, SPFA] Description 物流公司要把一批货物从码头A运到码头B.由于货物量比较大,需要\(n\)天才能运完.货物运输过程中一般要转 停好几个码头.物流公司通常会设计一条固定的运 ...
- Android自定义控件之自定义属性(二)
前言: 上篇介绍了自定义控件的基本要求以及绘制的基本原理,本篇文章主要介绍如何给自定义控件自定义一些属性.本篇文章将继续以上篇文章自定义圆形百分比为例进行讲解.有关原理知识请参考Android自定义控 ...
- [Servlet&JSP] 从JSP到Servlet
JSP与Servlet是一体的两面,JSP最后都会被容器转译为Servlet源码,自己主动编译为.class文件,载入.class文件然后生成Servlet对象. 由容器转译后的Servlet类具有_ ...
- android页面间传递对象
android传递对象有两种方式: 一种是Serializable和Parcelable 对于第一种方式: import java.io.Serializable; public class Shop ...
- xml文件的根节点layout_width或者layout_height设置无效果的原因分析
在android开发中相信大家对ListView.GridView等组建都非常熟悉,在使用它们的时候须要自己配置相关的Adapter,而且配置现骨干的xml文件作为ListView等组建的子View, ...
- 【每日Scrum】第五天(4.26) TD学生助手Sprint2站立会议
站立会议 组员 昨天 今天 困难 签到 刘铸辉 (组长) 今天增加了几个页面的子菜单,然后设计了几个要用的界面 今天和楠哥做了课程事件和日历表操作的例子,并尝试做时间表和日历表的数据库设计 安卓的数据 ...
- python--软件规范和反射
软件开发规范 写一个作业的时候,要将写的代码分开 bin文件夹里面第一个是start文件 核心代码都在core文件夹里面 文件core最好也是固定名字 BaseDir=os.path.dirna ...
- ActiveMQ 消息持久化到Mysql数据库
[root@txylucky local]# tar -zxvf apache-activemq-5.15.8-bin.tar.gz[root@txylucky local]# mv apache-a ...