Codeforces 872 A Search for Pretty Integers
来源:互联网 发布:php txt教程下载 编辑:程序博客网 时间:2024/06/08 09:44
题目地址
题意:给你两个集合a和b,容量分别为n和m,让你求出最小的数,包含了a中的一个数以及b中的一个数。
思路:排序+标记,我们先看有没有同时在a和b中出现的数,如果有的话,选最小的一个同时出现的数输出,如果没有的话就是把a和b集合分别排序,去每个集合中的最小值出来,然后二者的最小值当第一位,大者当后一位。
#include <iostream>#include <cstring>#include <string>#include <queue>#include <vector>#include <map>#include <set>#include <stack>#include <cmath>#include <cstdio>#include <algorithm>#define N 400010#define LL __int64#define inf 0x3f3f3f3f 0#define lson l,mid,ans<<1#define rson mid+1,r,ans<<1|1#define getMid (l+r)>>1#define movel ans<<1#define mover ans<<1|1const int mod = 1000000007;using namespace std;int num[N];int flag1[10];int a[N], b[N];int flag2[10];int main() { cin.sync_with_stdio(false); int n, m; while (cin >> n >> m) { memset(flag1, 0, sizeof(flag1)); memset(flag2, 0, sizeof(flag2)); for (int i = 0; i < n; i++) { cin >> a[i]; flag1[a[i]] = 1; } for (int i = 0; i < m; i++) { cin >> b[i]; flag2[b[i]] = 1; } for (int i = 1; i < 10; i++) { if (flag1[i] && flag2[i]) { cout << i << endl; return 0; } } sort(a, a + n); sort(b, b + m); cout << min(a[0],b[0]) << max(b[0],a[0]) << endl; } return 0;}
阅读全文
0 0
- Codeforces 872 A Search for Pretty Integers
- CodeForces 872A Search for Pretty Integers
- A. Search for Pretty Integers
- Codeforces Round #440 div2 A. Search for Pretty Integers
- Codeforces Round #440 A. Search for Pretty Integers
- codeforces Search for Pretty Integers(水)
- Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination) A. Search for Pretty Integers
- Codeforces 870A. Search for Pretty Int
- Codeforces Round #440 (Div. 2) Search for Pretty Integers
- Elimination Round 2-A. Search for Pretty Integers
- [LeetCode] Search for a Range (sorted integers array,find start & end position of a target number)
- Search for a Range
- Search for a Range
- Search for a Range
- Search for a Range !!!
- Search for a Range
- Search for a Range
- Search For A Range
- 第10章 快到碗里来——DirectX大局观认知
- Java生成PDF报表
- 一文总结学习 Python 的 14 张思维导图
- Codeforces 872 B Maximum of Maximums of Minimums
- leetcode 581 Shortest Unsorted Continuous Subarray
- Codeforces 872 A Search for Pretty Integers
- 欢迎使用CSDN-markdown编辑器
- 十大基础实用算法及其拓展
- sql中通过from接一个查询结果
- Java 计算两个日期相差的天数
- LeetCode689. Maximum Sum of 3 Non-Overlapping Subarrays
- linux-命令
- 1.1 HTTP基本概念
- filter与interceptor的区别