题意翻译

给出两个整数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. javascript高级程序设计--浅析undefined与null的差别

    浅析undefined与null的差别 相似处: 1.undefined 和 null 都是javascript 的基本数据类型.事实上两者没有太大差别. 定义: var a=undefined; v ...

  2. luogu2833 等式

    题目大意 给出\(a,b,c,x_1,x_2,y_1,y_2\),求满足\(ax+by+c=0\),且\(x\in[x1,x2],y\in [y1,y2]\)的整数解有多少对. 题解 用扩展欧几里得算 ...

  3. Mysql数据类型(二)

    字符类型 #官网:https://dev.mysql.com/doc/refman/5.7/en/char.html #注意:char和varchar括号内的参数指的都是字符的长度 #char类型:定 ...

  4. leetcode 几道题目

    是周六晚上的几道题,晚上11点半,睡的早,起不来! 494. Target Sum 分析:看完这题,看到数据范围,长度20,枚举就是1<<20 = 1e6, 然后单次20,总共就是2e8, ...

  5. HBase编程 API入门系列之modify(管理端而言)(10)

    这里,我带领大家,学习更高级的,因为,在开发中,尽量不能去服务器上修改表. 所以,在管理端来修改HBase表.采用线程池的方式(也是生产开发里首推的) package zhouls.bigdata.H ...

  6. 关于iscroll.js插件的使用

    iscroll 作用: 可以让区域滚动效果好看一些 使用: 1. html结构 外面必须包一层盒子,切内部的元素要尽量简单,不然会影响滚动效果 <div id="wrapper&quo ...

  7. (链接)IDEA 2018 激活 IDEA 2018.3激活教程 最新的(三种)—2018.11.26亲测

    破解不成功的请注意时效性,写于2019/2/8,以下第一种激活方法亲测可用, 不过有时候破解成功了可能过几天突然就打不开了,双击无反应的说,这时候再按顺序 操作一遍就是了: 1)把idea64.exe ...

  8. 移动web开发中自己遇到的三个小题及解决方法

    大家好! 这是我第二次写随笔感想,有不足之处希望大家提出,我也算的上一个小白,自己进入前端行业也刚刚半年,在这里半年里我遇到一个技术大牛的好领导,让我在项目中学到很多,想和大家分享一下! 一. 移动端 ...

  9. 使用JDK和axis2发布webservice

    最近使用webservice进行远程调用一直很火,自从JDK1.6版本发布后,发布一个webservice项目变得更加简单了 笔者由于工作的需要针对JDK和axis2如何发布webservice做过相 ...

  10. sql server中使用组合索引需要注意的地方

    一.使用组合索引需要注意的地方 1.索引应该建在选择性高的字段上(键值唯一的记录数/总记录条数),选择性越高索引的效果越好.价值越大,唯一索引的选择性最高: 2.组合索引中字段的顺序,选择性越高的字段 ...