Codeforces Round #440 (Div. 2) Search for Pretty Integers
来源:互联网 发布:淘宝网包包 编辑:程序博客网 时间:2024/05/21 18:24
You are given two lists of non-zero digits.
Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the smallest positive pretty integer?
The first line contains two integers n and m (1 ≤ n, m ≤ 9) — the lengths of the first and the second lists, respectively.
The second line contains n distinct digits a1, a2, ..., an (1 ≤ ai ≤ 9) — the elements of the first list.
The third line contains m distinct digits b1, b2, ..., bm (1 ≤ bi ≤ 9) — the elements of the second list.
Print the smallest pretty integer.
2 34 25 7 6
25
8 81 2 3 4 5 6 7 88 7 6 5 4 3 2 1
1
In the first example 25, 46, 24567 are pretty, as well as many other integers. The smallest among them is 25. 42 and 24 are not pretty because they don't have digits from the second list.
In the second example all integers that have at least one digit different from 9 are pretty. It's obvious that the smallest among them is 1, because it's the smallest positive integer.
这道题直接做就行了,可以用另外的数组来保存数字出现的次数,也可以开两个bool数组记录。
#include<iostream>#include<cstring>#include<algorithm>using namespace std;int main(){ int n,m; int a[11],b[11],v[11]; while(cin>>n>>m) { memset(v,0,sizeof(v)); for(int i=0;i<n;i++) { cin>>a[i]; v[a[i]]++; } for(int i=0;i<m;i++) { cin>>b[i]; v[b[i]]++; } for(int i=1;i<=9;i++) { if(v[i]==2) { cout<<i<<endl; return 0; } } sort(a,a+n); sort(b,b+n); cout<<min(a[0],b[0])<<max(a[0],b[0])<<endl; } return 0;}
- Codeforces Round #440 (Div. 2) Search for Pretty Integers
- Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination) A. Search for Pretty Integers
- Codeforces Round #440 div2 A. Search for Pretty Integers
- Codeforces Round #440 A. Search for Pretty Integers
- Elimination Round 2-A. Search for Pretty Integers
- Codeforces 872 A Search for Pretty Integers
- CodeForces 872A Search for Pretty Integers
- codeforces Search for Pretty Integers(水)
- A. Search for Pretty Integers
- 【Codeforces Round #422 (Div. 2) D】My pretty girl Noora
- Codeforces 870A. Search for Pretty Int
- Codeforces Round #289 (Div. 2, ACM ICPC Rules)E. Pretty Song
- Codeforces Round #289 (Div. 2, ACM ICPC Rules) E. Pretty Song
- Codeforces Round #289 (Div. 2, ACM ICPC Rules) E. Pretty Song
- Codeforces Round #289 (Div. 2, ACM ICPC Rules)E.Pretty Song
- Codeforces Round #289 (Div. 2, ACM ICPC Rules) E. Pretty Song
- Codeforces Round #289 (Div. 2, ACM ICPC Rules) E. Pretty Song
- Codeforces Round #289 (Div. 2, ACM ICPC Rules)E. Pretty Song(数学,想法题,好题)
- 解决:Ubuntu14.04使用vi编辑器时输入异常且按方向键乱码
- Syntax error, insert "Dimensions" to complete TypeArgument
- Lauren与密码学5,对称密码系统
- Codeforces 659F Polycarp and Hay【思维+并查集+Bfs】
- tensorflow ssd mobilenet模型训练
- Codeforces Round #440 (Div. 2) Search for Pretty Integers
- Saltstack自动化源码编译安装PHP以及LNMP安装整合
- MySQL学习阶段小结
- 计算机如是何启动的?
- 使用banner加载网路图片
- 操作系统之进程管理2
- WebStorm设置服务器-局域网内其他设备访问(移动端手机访问测试等)
- Volley源码分析
- Mybatis Insert 返回主键的一个小坑