Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2) A-C题解
来源:互联网 发布:网络 神曲 编辑:程序博客网 时间:2024/05/16 02:44
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.
看不懂题意,就是按照两组数有相同的就输出相同的,没有就输出两个数组中的最小值,按升序输出。
代码实现:
#include<iostream> #include<algorithm>#include<cstring>#include<cmath>#include<queue>#include<cstdio>#include<set>#define ll long long#define mset(a,x) memset(a,x,sizeof(a))using namespace std;const double PI=acos(-1);const int inf=0x3f3f3f3f;const double esp=1e-6;const int maxn=105;const int mod=1e9+7;int dir[4][2]={0,1,1,0,0,-1,-1,0};ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}ll lcm(ll a,ll b){return a/gcd(a,b)*b;}ll inv(ll b){if(b==1)return 1; return (mod-mod/b)*inv(mod%b)%mod;}ll fpow(ll n,ll k){ll r=1;for(;k;k>>=1){if(k&1)r=r*n%mod;n=n*n%mod;}return r;}int main(){int a[10],b[10],visita[10],visitb[10];int i,j,k,n,m;while(cin>>m>>n){mset(visita,0);mset(visitb,0);for(i=0;i<m;i++){cin>>a[i];visita[a[i]]=1;}for(j=0;j<n;j++){cin>>b[j];visitb[b[j]]=1;}int flag=0,temp;for(i=0;i<10;i++)if(visita[i]&&visitb[i]){flag=1;temp=i;break;}if(flag){cout<<temp<<endl;}else{sort(a,a+m);sort(b,b+n);if(a[0]>b[0])swap(a[0],b[0]);cout<<a[0]<<b[0]<<endl;}}return 0;}
- Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2) A-C题解
- Codeforces Round #454 (Div. 2, based on Technocup 2018 Elimination Round 4) A-C
- Codeforces Round #434 (Div. 1, based on Technocup 2018 Elimination Round 1) A-C题解
- Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination) A. Search for Pretty Integers
- Codeforces Round #454 (Div. 2, based on Technocup 2018 Elimination Round 4) A
- Codeforces Round #434 (Div. 2, based on Technocup 2018 Elimination Round 1) C
- Codeforces Round #454 (Div. 2, based on Technocup 2018 Elimination Round 4) C
- Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2)
- Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2)
- Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2)
- Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2) 总结
- Codeforces Round #380 (Div. 2,Based on Technocup 2017 - Elimination Round 2)C - Road to Cine//
- Codeforces Round #434 (Div. 2, based on Technocup 2018 Elimination Round 1)
- Codeforces Round #434 (Div. 2, based on Technocup 2018 Elimination Round 1)
- Codeforces Round #434 (Div. 2, based on Technocup 2018 Elimination Round 1) D
- Codeforces Round #434 (Div. 2, based on Technocup 2018 Elimination Round 1) ABCDF
- Codeforces Round #445 (Div. 2, based on Technocup 2018 Elimination Round 3)
- Codeforces Round #445 (Div. 2, based on Technocup 2018 Elimination Round 3)
- Python 开发工具Pycharm
- 非线性最小二乘
- Axon Framework官方文档(三)
- 第七周项目二 定义链队存储结构,实现其基本运算.
- php-cli和php-fpm的关系是什么?
- Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2) A-C题解
- Hibernate与MyBatis的比较
- 调休结构图
- 编程思想与生活经验
- 31.du
- Python列表简介
- 对分页的理解
- R-CNN之前的准备:Efficient Graph-Based Image Segmentation
- FPGA 中时钟信号的总结