CODE FESTIVAL 2017 qual B B - Problem Set水体,stl map
Posted ╰追憶似水年華ぃ╮
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CODE FESTIVAL 2017 qual B B - Problem Set水体,stl map相关的知识,希望对你有一定的参考价值。
CODE FESTIVAL 2017 qual B B - Problem Set
确实水题,但当时没想到map,用sort后逐个比较解决的,感觉麻烦些,虽然效率高很多。map确实好写点。
用map:
1 #include<iostream> 2 #include<cstdio> 3 #include<cstdlib> 4 #include<map> 5 using namespace std; 6 map<int,int>mp; 7 8 int main() 9 { 10 int n,m,x; 11 cin>>n; 12 for(int i=0;i<n;i++){ 13 cin>>x; 14 mp[x]++; 15 } 16 cin>>m; 17 for(int i=0;i<m;i++){ 18 cin>>x; 19 if(mp[x]==0){ 20 cout<<"NO"<<endl; 21 exit(0); 22 }else mp[x]--; 23 } 24 cout<<"YES"<<endl; 25 return 0; 26 }
直接sort
1 #include<cstdio> 2 #include<algorithm> 3 using namespace std; 4 const int maxn = 200500; 5 int d[maxn], t[maxn]; 6 7 int main() 8 { 9 int N, M; 10 scanf("%d", &N); 11 for (int i = 1; i <= N; i++) scanf("%d", &d[i]); 12 scanf("%d", &M); 13 for (int i = 1; i <= M; i++) scanf("%d", &t[i]); 14 sort(d+1, 1 + N+d); 15 sort(t+1, 1 + M+t); 16 int p1 = 1, p2 = 1; 17 bool flag = false; 18 while (p1<=M&&p2<=N) 19 { 20 if (p1 != M) { 21 if (d[p2] == t[p1]) { 22 p2++, p1++; 23 } 24 else { 25 p2++; 26 } 27 } 28 else 29 { 30 if (d[p2] == t[p1]) { 31 flag = true; 32 break; 33 } 34 else 35 { 36 p2++; 37 } 38 } 39 } 40 if (flag) printf("YES\n"); 41 else printf("NO\n"); 42 return 0; 43 }
以上是关于CODE FESTIVAL 2017 qual B B - Problem Set水体,stl map的主要内容,如果未能解决你的问题,请参考以下文章
CODE FESTIVAL 2017 qual B 解题报告
101 to 010 Atcoder CODE FESTIVAL 2017 qual B D
CODE FESTIVAL 2017 qual B B - Problem Set水体,stl map
[Atcoder Code Festival 2017 Qual B Problem F]Largest Smallest Cyclic Shift