标签:targe nbsp logs main contest map set http class
确实水题,但当时没想到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】
标签:targe nbsp logs main contest map set http class
原文地址:http://www.cnblogs.com/zxhyxiao/p/7668214.html