CF870A Search for Pretty Integers

Posted 一蓑烟雨任生平

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CF870A Search for Pretty Integers相关的知识,希望对你有一定的参考价值。

题意翻译

给出两个整数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[11],b[11];
int main(){
    cin>>n>>m;
    for(int i=1;i<=n;i++)    scanf("%d",&a[i]);
    for(int i=1;i<=m;i++)    scanf("%d",&b[i]);
    sort(a+1,a+1+n);
    sort(b+1,b+1+m);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            if(a[i]==b[j]){
                cout<<a[i]<<endl;
                return 0;
            }
    if(a[1]>b[1])    cout<<b[1]*10+a[1]<<endl;
    else    cout<<a[1]*10+b[1]<<endl;
}

 

以上是关于CF870A Search for Pretty Integers的主要内容,如果未能解决你的问题,请参考以下文章

跨域请求被阻止:同源策略不允许在 http://localhost:9200/test12/test3/_search?pretty 读取远程资源

2017年10月18日 畅游CF div2划水模式

elastic search 常用查询

CF528D Fuzzy Search

Pretty UI Design For Android -- 滑动背景透明列表

[CF528D]Fuzzy Search