Codeforces Round #440 div2 A. Search for Pretty Integers

EPLAN 设备接线图模板制作 属性摆放 设备连接图设置(选项 - - 设置) 连接图生成 阅读详情
A. Search for Pretty Integers
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given two lists of non-zero digits.

Let's call an integer pretty if its (base 10) 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?

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 9) — the lengths of the first and the second lists, respectively.

The second line contains n distinct digits a1, a2, ..., an (1 ≤ ai ≤ 9) — the elements of the first list.

The third line contains m distinct digits b1, b2, ..., bm (1 ≤ bi ≤ 9) — the elements of the second list.

Output

Print the smallest pretty integer.

Examples
input
2 3
4 2
5 7 6
output
25
input
8 8
1 2 3 4 5 6 7 8
8 7 6 5 4 3 2 1
output
1
Note

In the first example 25, 46, 24567 are pretty, as well as many other integers. The smallest among them is 25. 42 and 24 are 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 9 are pretty. It's obvious that the smallest among them is 1, because it's the smallest positive integer.

题意 输入n,m,接下来两行为两个序列,如果两个序列中有相同的输出相同的最小的那个数,如果没有就从两个序列中分别取出一个数,输出这两个数组成的最小两位数。

桶排序就好


#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <set>
#include <stack>
#include <queue>
#include <vector>
#include <cmath>
using namespace std;

#define ll long long 
#define mem(a, b) memset(a, b, sizeof(a))
#define inf 0x3f3f3f3f
#define mod 10000000007
#define Maxn 10000005
#define debug() puts("F*** you every!");

int main()
{
	int n, m, a[50], b[50], w;
	mem(a, 0);
	mem(b, 0);
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i ++) {
		scanf("%d", &w);
		a[w]++;
	}
	for (int i = 0; i < m; i++) {
		scanf("%d", &w);
		b[w]++;
	}
	int flag = 0;
	for (int i = 1; i < 10; i ++) {
		if (a[i] != 0 && b[i] != 0)
		{
			printf("%d\n", i);
			flag = 1;
			break;
		}
	}
	int s1, s2;
	if (flag == 0) {
		for (int i = 0; i < 10; i ++) { 
			if (a[i] != 0) {
				s1 = i;break;
			}
		}
		for (int i = 0; i < 10; i ++) { 
			if (b[i] != 0) {
				s2 = i;break;
			}
		}
		printf("%d%d\n", s1 > s2 ? s2 : s1, s1 <= s2 ? s2 : s1);
	}
		
	
}



汉书HE8,好用的汇编代码编写工具 汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大 立即下载

相关推荐

STM32CubeMX安装避坑指南:为什么你的Java环境总是报错?

本文针对STM32CubeMX安装过程中最常见的Java环境报错问题,提供了一套完整的诊断与解决方案。文章深入剖析了JRE版本冲突、环境变量配置错误、路径权限等核心原因,并给出了从系统级检查到手动修正环境变量的详细步骤,帮助开发者彻底解决安装难题,顺利开启STM32开发之旅。

prometheus9mon的博客 226

codeforces 872aSearch for Pretty Integers

http://www.elijahqi.win/archives/1253 You are given two lists of non-zero digits. Let’s call an integer pretty if its (base 10) representation has at least one digit from the first list and at leas...

Elijahqi 300

【DMA】认识 DMA 及其工作流程(与传统CPU存取方式的区别)

【DMA】认识 DMA 及其工作流程(与传统CPU存取方式的区别)

challenglistic的博客 5万+

Codeforces Round #440 A. Search for Pretty Integers

A. Search for Pretty Integers time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given two lists of non

aaakirito的博客 477

Maltab GUI课程设计——网络爬虫程序(基金连涨连跌提醒)

Maltab GUI课程设计——网络爬虫程序(基金连涨连跌提醒)

果果爱腰果的博客 849

2021电子科技大学分布式系统期末考点精析与实战解析

本文深入解析2021年电子科技大学分布式系统期末考试核心考点,包括分布式事务、时钟同步、GFS架构等高频内容。基于回忆版试题,提供实战解析与应试技巧,帮助考生高效复习。重点涵盖两阶段提交、Cristian算法等关键技术,适合计算机专业学生备考参考。

weixin_29251131的博客 539

A. Search for Pretty Integers

time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given two lists of non-zero digits. Let's call an inte

无知的我 879

使用 Java + PaddleOCR 实现表格识别,支持导出 HTML 和 Excel(附源码)

使用Java+PaddleOCR快速搭建表格识别系统,无需处理底层模型细节。系统支持表格结构识别和内容识别,可将图片转换为可编辑表格格式。文章提供了完整的实现流程,包括Maven依赖引入、模型下载(包含检测、识别、分类和表格结构模型)及参数配置说明。SmartJavaAI支持多种高性能模型选择,适用于不同应用场景,帮助开发者快速实现表格识别功能。

deng775747758的博客 1473

Codeforces 870A. Search for Pretty Int

A. Search for Pretty Integers time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given two lists of non

shyoldman的博客 626

医疗影像分割 | 使用MedSAM训练自己的医学图像分割数据集

摘要 本文详细介绍了使用MedSAM模型训练自定义医学图像数据集的完整流程。主要内容包括:代码下载与环境配置(创建虚拟环境、安装依赖、验证CUDA)、数据集准备(目录结构、格式要求、命名规范及检查工具)、预训练模型下载(不同模型选择建议),以及训练脚本修改(解决文件名匹配、Windows系统NCCL支持、单GPU训练等常见问题)。通过逐步指导,帮助用户快速搭建MedSAM训练环境并适配自己的医学图像数据,实现高效的分割模型训练。

LiRongLu_的博客 488

湿式双离合器自动变速器simulink建模与仿真

随着汽车工业的不断发展,自动变速器在提高汽车性能、驾驶舒适性和燃油经济性等方面发挥着越来越重要的作用。湿式双离合器自动变速器(Wet Dual-Clutch Transmission,简称 WDCT)作为一种先进的自动变速器技术,具有换挡速度快、动力传递平稳、燃油经济性好等优点,被广泛应用于各类汽车中。结构组成湿式双离合器自动变速器主要由双离合器、齿轮传动系统、液压控制系统和电子控制系统等部分组成。双离合器:由两个独立的离合器组成,分别控制奇数挡和偶数挡。通过切换两个离合器的工作状态,可以实现快速换挡。

平时工作较为繁忙,私信消息一般晚上回复,谢谢大家~~ 348

【LDU】2017级个人训练赛#1

A - The Artful Expedient http://codeforces.com/problemset/problem/869/A Rock... Paper! After Karen have found the deterministic winning (losing?) strategy for rock-paper-scissor

Z_sea的博客 705

ABB机器人刷功能选项全一篇就够——不怕丢失程序和IO配置数据

ABB机器人刷功能选项

m0_66701835的博客 1259

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

【链接】 我是链接,点我呀:) 【题意】 在这里输入题意 【题解】 先枚举一个数字的情况。 再枚举两个数的情况就好。 【代码】 #include <bits/stdc++.h> #define ll long long using namespace std; const int N = 20; int a[N],b[N],n,m; int main...

AWCXV 99

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination) A. Search for Pretty Integers

A. Search for Pretty IntegersProblem Statement     You are given two lists of non-zero digits.     Let’s call an integer pretty if its (base 10) representation has at least one digit from the firs

Ephemeral 319

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

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

A. Search for Pretty Integers time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given two lists of non

0.0 403

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

Codeforces Round #440 (A-C ) 题解

A 题 A. Search for Pretty Integers time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given two lists o...

weixin_30677073的博客 179

Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2) A-C题解

A. Search for Pretty Integers time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output You are given two lists of non-zero digits. Let's call an integer pretty if its (base 10) representation has at least on

Ever_glow的博客 713

Codeforces 870A

A. Search for Pretty Integerstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two lists of non-zero digits.Let's call an integer prett...

pigofzhou的博客 261

codeforces Search for Pretty Integers(水)

http://codeforces.com/contest/870/problem/A 题意:就是如果两个集合中有共同元素的话,就输出共同元素,如果没有共同元素的话就输出两个集合中的可以组成的最小的数。 思路:桶排水题。比较坑的是,两个有共同元素的时候输出共同元素。当时因为这个原因worng了两发,心态巨崩,然后代码写的也很丑 了,, #include #include #inc

wjmwsgj的博客 410

Codeforces 872 A Search for Pretty Integers

题目地址 题意:给你两个集合a和b,容量分别为n和m,让你求出最小的数,包含了a中的一个数以及b中的一个数。 思路:排序+标记,我们先看有没有同时在a和b中出现的数,如果有的话,选最小的一个同时出现的数输出,如果没有的话就是把a和b集合分别排序,去每个集合中的最小值出来,然后二者的最小值当第一位,大者当后一位。

不要錯過才珍惜 500

CodeForces - 872A Search for Pretty Integers

You are given two lists of non-zero digits. Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What i...

还我笑颜 221

Codeforces Round #440 A. Search for Pretty Integers

题目链接:http://codeforces.com/contest/872/problem/A 题意:给你两个集合,输出一个由这两个集合的数组成的最小数,注意:有相同数的话,可能只有一位 思路:分别找出两个集合中的相同的数,其次找出两个集合中最小的数,如果有相同数集不为空,那么就输出其中最小的数,否则就是这两个最小的数组成的最小数(小的放前面) AC代码:#include #includ

可我只是梦呓,半生半生的无力 209

Codeforces Round #440

You are given several queries. In the i-th query you are given a single positive integer ni. You are to represent ni as a sum of maximum possible number of composite summands and print this maximum num

yqdjl6的博客 436

CodeForces 872A Search for Pretty Integers

题目链接:http://codeforces.com/contest/872/problem/A 题意:给你两个序列,一个长度为n的序列a,和长度为m的序列b,现在给你一个定义叫做漂亮数,漂亮数至少有一个数是来自a序列,至少有一个数来自b序列,现让你输出最小的漂亮数 解析:有为a和b序列的范围0~9,所以最小的漂亮数一定是两位数,那你从1到100枚举一下,判断是否合法即可#include <bi

22h's Blog 582

Codeforces 870

Akatsuki

Akatsuki 757
上一篇: Codeforces Round #440 div2 B Maximum of Maximums of Minimums
下一篇: Codeforces Round #440 div2 C. Maximum splitting
Star77777
博客等级 码龄10年 104粉丝 95原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值