0
点赞
收藏
分享

微信扫一扫

A. Common Subsequence(水题)Codeforces Round #658 (Div. 2)

香小蕉 2022-06-24 阅读 90

原题链接: ​​https://codeforces.com/contest/1382/problem/A​​

A. Common Subsequence(水题)Codeforces Round #658 (Div. 2)_自定义
测试样例

input
5
4 5
10 8 6 4
1 2 3 4 5
1 1
3
3
1 1
3
2
5 3
1000 2 2 2 3
3 1 5
5 5
1 2 3 4 5
1 2 3 4 5
output
YES
1 4
YES
1 3
NO
YES
1 3
YES
1 2

Note

In the first test case, A. Common Subsequence(水题)Codeforces Round #658 (Div. 2)_#define_02 is a subsequence of A. Common Subsequence(水题)Codeforces Round #658 (Div. 2)_自定义_03 and A. Common Subsequence(水题)Codeforces Round #658 (Div. 2)_自定义_04. This array has length A. Common Subsequence(水题)Codeforces Round #658 (Div. 2)_ios_05, it is the smallest possible length of a subsequence of both A. Common Subsequence(水题)Codeforces Round #658 (Div. 2)_自定义_06 and A. Common Subsequence(水题)Codeforces Round #658 (Div. 2)_ios_07.

In the third test case, no non-empty subsequences of both A. Common Subsequence(水题)Codeforces Round #658 (Div. 2)_自定义_08 and A. Common Subsequence(水题)Codeforces Round #658 (Div. 2)_#define_09 exist, so the answer is “NO”.

题意: 给你两个数组,求他们的最短公共子序列,若没有,则输出NO。

解题思路: 妥妥的水题,最短就为1,再短就不存在,所以只要判断有无公共元素即可。具体看代码。(PS:比赛一定要先把题过一遍,因为你不知道哪一题是签到题。)

AC代码

/*

*
*/
#include<bits/stdc++.h> //POJ不支持

#define rep(i,a,n) for (int i=a;i<=n;i++)//i为循环变量,a为初始值,n为界限值,递增
#define per(i,a,n) for (int i=a;i>=n;i--)//i为循环变量, a为初始值,n为界限值,递减。
#define pb push_back
#define IOS ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define fi first
#define se second
#define mp make_pair

using namespace std;

const int inf = 0x3f3f3f3f;//无穷大
const int maxn = 1e5;//最大值。
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
//*******************************分割线,以上为自定义代码模板***************************************//

int t;
int n,m;
int a[maxn],b[maxn];
int main(){
//freopen("in.txt", "r", stdin);//提交的时候要注释掉
IOS;
while(cin>>t){
while(t--){
map<int,int> p;
cin>>n>>m;
rep(i,0,n-1){
cin>>a[i];
p[a[i]]++;
}
bool flag=false;
int result;
rep(i,0,m-1){
cin>>b[i];
if(flag==false&&p.count(b[i])>0){
result=b[i];
flag=true;
}
}
if(flag){
cout<<"YES"<<endl;
cout<<1<<" "<<result<<endl;
}
else{
cout<<"NO"<<endl;
}
}
}
return 0;
}


举报

相关推荐

0 条评论