题意翻译

给出两个整数n,m,a数组有n个数,b数组有m个数。求一个数,这个数的每一位必须在a数组和b数组中至少出现过一次,求符合条件的数当中最小的数。

Translated by @我是lyy

题目描述

You are given two lists of non-zero digits.

Let's call an integer pretty if its (base 1010 ) 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 nn and mm ( 1<=n,m<=91<=n,m<=9 ) — the lengths of the first and the second lists, respectively.

The second line contains nn distinct digits a_{1},a_{2},...,a_{n}a1​,a2​,...,an​ ( 1<=a_{i}<=91<=ai​<=9 ) — the elements of the first list.

The third line contains mm distinct digits b_{1},b_{2},...,b_{m}b1​,b2​,...,bm​ ( 1<=b_{i}<=91<=bi​<=9 ) — the elements of the second list.

输出格式:

Print the smallest pretty integer.

输入输出样例

输入样例#1: 复制

2 3
4 2
5 7 6
输出样例#1: 复制

25
输入样例#2: 复制

8 8
1 2 3 4 5 6 7 8
8 7 6 5 4 3 2 1
输出样例#2: 复制

1

说明

In the first example 2525 , 4646 , 2456724567 are pretty, as well as many other integers. The smallest among them is 2525 . 4242 and 2424are 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 99 are pretty. It's obvious that the smallest among them is 11 , because it's the smallest positive integer.

#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n,m;
int a[],b[];
int main(){
cin>>n>>m;
for(int i=;i<=n;i++) scanf("%d",&a[i]);
for(int i=;i<=m;i++) scanf("%d",&b[i]);
sort(a+,a++n);
sort(b+,b++m);
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
if(a[i]==b[j]){
cout<<a[i]<<endl;
return ;
}
if(a[]>b[]) cout<<b[]*+a[]<<endl;
else cout<<a[]*+b[]<<endl;
}

CF870A Search for Pretty Integers的更多相关文章

  1. codeforces Round #440 A Search for Pretty Integers【hash/排序】

    A. Search for Pretty Integers [题目链接]:http://codeforces.com/contest/872/problem/A time limit per test ...

  2. 【Codeforces Round #440 (Div. 2) A】 Search for Pretty Integers

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 先枚举一个数字的情况. 再枚举两个数的情况就好. [代码] #include <bits/stdc++.h> #defi ...

  3. Codeforces Round #440 (Div. 2) A,B,C

    A. Search for Pretty Integers time limit per test 1 second memory limit per test 256 megabytes input ...

  4. Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2)

    A. Search for Pretty Integers 题目链接:http://codeforces.com/contest/872/problem/A 题目意思:题目很简单,找到一个数,组成这个 ...

  5. Codeforces Round #440 (Div. 2)【A、B、C、E】

    Codeforces Round #440 (Div. 2) codeforces 870 A. Search for Pretty Integers(水题) 题意:给两个数组,求一个最小的数包含两个 ...

  6. Codeforces Contest 870 前三题KEY

    A. Search for Pretty Integers: 题目传送门 题目大意:给定N和M个数,从前一个数列和后一个数列中各取一个数,求最小值,相同算一位数. 一道水题,读入A.B数组后枚举i.j ...

  7. ACM-ICPC (10/15) Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2)

    A. Search for Pretty Integers You are given two lists of non-zero digits. Let's call an integer pret ...

  8. [LeetCode] Search a 2D Matrix II 搜索一个二维矩阵之二

    Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the follo ...

  9. [LeetCode] Search a 2D Matrix 搜索一个二维矩阵

    Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the follo ...

随机推荐

  1. IOS UITextView光标位置在中间的问题

    在viewDidLoad中 if ([selfrespondsToSelector:@selector(setAutomaticallyAdjustsScrollViewInsets:)]) { se ...

  2. POJ2228 Naptime 环形DP

    题目大意:牛在第i个小时睡觉能够恢复U[i]点体力.睡觉时第一小时不恢复体力.一天的N小时连着下一天的1小时.求能够恢复体力的和的最大值. 定义DP[i][j][0]为前i个小时休息了j个小时,i小时 ...

  3. luogu2014 选课 背包类树形DP

    题目大意:有N门功课,每门课有个学分,每门课有一门或没有直接先修课(若课程a是课程b的先修课即只有学完了课程a,才能学习课程b).一个学生要从这些课程里选择M门课程学习,问他能获得的最大学分是多少? ...

  4. hdoj--5620--KK's Steel(斐波那契数)

    KK's Steel Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total ...

  5. nginx配置访问密码,让用户输入用户名密码才能访问

    如果我们在 nginx 下搭建了一些站点,但是由于站点内容或者流量的关系,我们并不想让所有人都能正常访问,那么我们可以设置访问认证.只有让用户输入正确的用户名和密码才能正常访问.效果如下: 在 ngi ...

  6. 自定义typecho后台路径

    如何自定义后台路径 Typecho 安装好后,默认的后台路径是 domain.com/admin/,为了提高安全性,我们允许以 domain.com/xxxx/ 的方式访问,其中 xxxx 是你自定义 ...

  7. hdu2236 无题II 最大匹配 + 二分搜索

    中文题目,题意大家都明白. 看到“不同的行和列”就觉得要用二分匹配来做.要求最大值与最小值的差值最小,是通过枚举边的下限和上限来完成. 枚举过程是这样的,在输入的过程可以记录下边权的最大值MAX和最小 ...

  8. Spring DATA MongoDB @DBref查询,or和and联合查询

    @DBref文档关联,在按该类型查询的时候,在字段名后加上关联表的字段名即可,如: Criteria.where("bloggroup.$id"), $id代表关联表的oid字段. ...

  9. win 运行

    1.msconfig - 系统配置 - 服务-全部禁用 2.DXDIAG  direct版本

  10. Python笔记8----DataFrame(二维)

    目录: DataFrame概念 DataFrame创建 基本操作 查看.索引 修改.删除 统计功能 条件筛选 合并 去除空值 4. 一些常用的函数 apply memory_usage pivot_t ...