CODE FESTIVAL 2017 qual B B - Problem Set【水题,stl map】

CODE FESTIVAL 2017 qual B B - Problem Set

确实水题,但当时没想到map,用sort后逐个比较解决的,感觉麻烦些,虽然效率高很多。map确实好写点。

用map:

 #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<map>
using namespace std;
map<int,int>mp; int main()
{
int n,m,x;
cin>>n;
for(int i=;i<n;i++){
cin>>x;
mp[x]++;
}
cin>>m;
for(int i=;i<m;i++){
cin>>x;
if(mp[x]==){
cout<<"NO"<<endl;
exit();
}else mp[x]--;
}
cout<<"YES"<<endl;
return ;
}

直接sort

 #include<cstdio>
#include<algorithm>
using namespace std;
const int maxn = ;
int d[maxn], t[maxn]; int main()
{
int N, M;
scanf("%d", &N);
for (int i = ; i <= N; i++) scanf("%d", &d[i]);
scanf("%d", &M);
for (int i = ; i <= M; i++) scanf("%d", &t[i]);
sort(d+, + N+d);
sort(t+, + M+t);
int p1 = , p2 = ;
bool flag = false;
while (p1<=M&&p2<=N)
{
if (p1 != M) {
if (d[p2] == t[p1]) {
p2++, p1++;
}
else {
p2++;
}
}
else
{
if (d[p2] == t[p1]) {
flag = true;
break;
}
else
{
p2++;
}
}
}
if (flag) printf("YES\n");
else printf("NO\n");
return ;
}
上一篇:Android 学习手札(一) 应用程序架构


下一篇:hdu 2117:Just a Numble(水题,模拟除法运算)