HDU5166Missing number
来源:互联网 发布:阿里巴巴外贸绑定域名 编辑:程序博客网 时间:2024/06/10 20:01
Missing number
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 936 Accepted Submission(s): 471
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≤10 )
For each test case , the first line contains a integersn , which means the number of numbers the permutation has. In following a line , there are n distinct postive integers.(1≤n≤1,000 )
For each test case , the first line contains a integers
Output
For each case output two numbers , small number first.
Sample Input
233 4 511
Sample Output
1 22 3
题目比较水,不懂题意的去best code里面看看中文版的:http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=564&pid=1001
不过这里还是给不了解题意的小伙伴们说下:给定一个排列,小yb不小心弄丢了这个排列中的两个数字,输入数据中给出的是小明现在手上有的序列,要求得丢失的那两个数列,并且按从小到大的顺序输出就好了;从给出的数据我们很容易就可以推断,这个所给的数列就是 1至n+2 ,不然题目没法下笔,可以抱着试试的心态去写下,提交AC了证明是对的,所以就不要纠结于推断这个排列为什么会是这样的了;
给出代码:
#include<iostream>#include<cstdio>#include<string>#include<algorithm>using namespace std;int main(){int T, n;int num[1000];cin >> T;while (T--){cin >> n;for (int i = 1; i <= n; i++)cin >> num[i];sort(num+1, num+n+1);int count=1;//记录输出了几个数;int j;for (int i = 1,j=1; i <= n + 2; i++){if (count < 2){if (i == num[j]){j++;continue;}else if (count == 1){count++;cout << i;}else if (count==2){cout << " " << i << endl;count++;}}else break;}}return 0;}
1 0
- HDU5166Missing number
- Number
- number
- number
- Number
- number
- number
- Number
- Number
- NUMBER
- Number
- Number()
- number
- Number
- Number
- E: number number number
- 1005 number number number
- HDU6198 number number number
- VirtualBox提示Unable to load R3 module
- Laravel框架下,wamp中数据库的迁移,踩过的坑
- Android Material Design:滑动指示选项卡android.support.design.widget.TabLayout的简单使用
- windows下PHP7安装方法(ts版和nts版)
- Android异步加载图片中UI是否被阻塞的测试
- HDU5166Missing number
- Java微博爬虫的学习
- VS2008 ClickOnce发布Xenocode混淆的应用
- iOS系统UITextField研究
- Unity+NGUI性能优化方法总结
- linux和windows下的“回车符”和“换行符”
- 伴随ListView、RecyclerView、ScrollView滚动滑入滑出小图标--第三方开源--FloatingActionButton
- Discuz!X2.5 在FastCGI模式下php-cgi.exe进程数量增多的原因分析
- has a / is a 的区别