zoukankan      html  css  js  c++  java
  • 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;
    }
    细雨斜风作晓寒。淡烟疏柳媚晴滩。入淮清洛渐漫漫。 雪沫乳花浮午盏,蓼茸蒿笋试春盘。人间有味是清欢。
  • 相关阅读:
    在Eclipse中指定JDK
    VMware桥接模式下主机和和虚机间互相ping不通的处理方法
    CentOS7系列--10.1CentOS7中的GNOME桌面环境
    CentOS7系列--5.3CentOS7中配置和管理Kubernetes
    CentOS7系列--5.2CentOS7中配置和管理Docker
    CentOS7系列--5.1CentOS7中配置和管理KVM
    CentOS7系列--4.1CentOS7中配置DNS服务
    CentOS7系列--3.2CentOS7中配置iSCSI服务
    移动web开发(一)——移动web开发必备知识
    文章索引
  • 原文地址:https://www.cnblogs.com/cangT-Tlan/p/8442612.html
Copyright © 2011-2022 走看看