HDU
来源:互联网 发布:善领p46最新数据 编辑:程序博客网 时间:2024/06/02 00:28
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5166
题目描述
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 (n) , which means the number of numbers the permutation has. In following a line , there are nn distinct postive integers.(1≤n≤1,0001≤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
解题思路
题意是要补全第二行中的数字,使它连续,如果要添加的数有多种情况的话,输出小数,
因为是从 1 开始的,所以数据不大,直接用桶标记,即mark数组,用flag标记输出的个数,从1开始遍历,优先输出小的
注意第二次要初始化mark数组
AC代码
#include<iostream>#include<cmath>#include<cstring>using namespace std;int main () { int t; int a; int mark[1010]; cin >> t; while(t--) { int n; cin >> n; memset(mark, 0, sizeof(mark)); for(int i = 0; i < n; i++) { cin >> a; mark[a] = 1; } int flag = 0; int i = 1; while(flag <= 1) { if(mark[i] == 0) { if(flag == 0) printf("%d ", i); else if(flag == 1) printf("%d\n", i); flag++; } i++; } } return 0;}
阅读全文
0 0
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- hdu-
- hdu
- hdu
- hdu
- HDU
- android常用控件三(图片框ImageView, SD文件读取)
- mc.exe在VS上的配置方式
- Akka并发编程——第四节:Actor模型(三)
- 去除重复字符串
- Hadoop相关概念
- HDU
- 【剑指offer】面试题 33:二叉搜索树的后序遍历序列
- Codeforecs XOR On Segment 线段树(区间异或,求和)
- linux debian系统的两台主机之间建立安全信任关系及scp传输文件的免密操作
- 数据库第一天基础知识
- leetcode[Fizz Buzz]//待整理多种解法
- 选择排序
- 程序员日常工作英文20170718
- HTML入门笔记7-粗体、斜体和下划线标签