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.
输入输出样例
说明
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的更多相关文章
- 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 ...
- 【Codeforces Round #440 (Div. 2) A】 Search for Pretty Integers
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 先枚举一个数字的情况. 再枚举两个数的情况就好. [代码] #include <bits/stdc++.h> #defi ...
- 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 ...
- Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2)
A. Search for Pretty Integers 题目链接:http://codeforces.com/contest/872/problem/A 题目意思:题目很简单,找到一个数,组成这个 ...
- Codeforces Round #440 (Div. 2)【A、B、C、E】
Codeforces Round #440 (Div. 2) codeforces 870 A. Search for Pretty Integers(水题) 题意:给两个数组,求一个最小的数包含两个 ...
- Codeforces Contest 870 前三题KEY
A. Search for Pretty Integers: 题目传送门 题目大意:给定N和M个数,从前一个数列和后一个数列中各取一个数,求最小值,相同算一位数. 一道水题,读入A.B数组后枚举i.j ...
- 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 ...
- [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 ...
- [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 ...
随机推荐
- SWERC13 Trending Topic
map暴力. .. Imagine you are in the hiring process for a company whose principal activity is the analys ...
- 国产芯片任重道远 国科微SSD主控芯片的“追赶之路”(不能只提供一颗芯片,而是要将芯片、国密算法、固件Firmware、BIOS和操作系统紧密联系在一起,变成完整解决方案交给行业用户,才能真正体现自身的价值)
集微网消息,“中国芯”战略之路道阻且长,踏入这个赛道的攻坚者们需要十年如一日的技术突破,需要集合产业势能,共同协作,方能建立中国核心技术真正的竞争力. 国产化之路任重道远,SSD芯片初见成效 信息时代 ...
- hdoj--迷宫问题
迷宫问题 Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other) Total Submiss ...
- Constructing Roads --hdoj
Constructing Roads Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) ...
- Tool-Java:Eclipse
ylbtech-Tool-Java:Eclipse Eclipse 是一个开放源代码的.基于Java的可扩展开发平台.就其本身而言,它只是一个框架和一组服务,用于通过插件组件构建开发环境.幸运的是,E ...
- 05.使用jdk发布webservice服务
无论服务端是用什么写的,使用框架写的还是用jdk写的,它都会发布出来这样一个东西.主要你遵循咱们这七个步骤来走就可以调用了. 咱们现在转换一下角色,自己发布一个服务让别人去调.怎么来发布一个服务? 我 ...
- iOS 应用开发入门指南
前言:http://www.guomii.com/posts/20250安装工具:http://www.guomii.com/posts/20255工具:http://www.guomii.com/p ...
- mysql的递归(使用函数)
getChildList: BEGIN #声明两个局部变量 ); ); #初始化局部变量 SET sTemp = ''; #调用cast函数将int转换为char SET sTempChd = roo ...
- img和div的宽度不一样问题和li之间空隙问题的解决方案
img和div宽度不一致问题 今天写代码,遇到一个小问题,我把一张图片放进一个div里,然后没有设置任何的padding和margin,但是发现图片和div的高度不一样,在img的下方出现了3px的空 ...
- Hibernate框架学习(十)——查询优化
一.类级别查询 1.get方法:没有任何策略,调用即立即查询数据库加载数据. 2.load方法:是在执行时不发送任何SQL语句,返回一个对象,使用该对象时才执行查询:应用类级别的加载策略. 1> ...