NYOJ-626-intersection set(二分查找)

 题目链接

 1 /*
 2     Name:NYOJ-626-intersection set
 3     Copyright:
 4     Author:
 5     Date: 2018/4/12 21:30:10
 6     Description:
 7     二分查找水题 
 8 */
 9 #include <iostream>
10 #include <algorithm> 
11 #include <set>
12 #include <cstdio>
13 using namespace std;
14 int nums1[50005], nums2[50005];
15 int main()
16 {
17     ios::sync_with_stdio(false);
18     int m, n;
19     while (~scanf("%d %d", &m,&n)) {
20         int tmp;
21         for (int i=0; i<m; i++) {
22             scanf("%d", &nums1[i]);
23         }
24         for (int i=0; i<n; i++) {
25             scanf("%d", &nums2[i]);
26         }
27         sort(nums1, nums1+m);
28         sort(nums2, nums2+n);
29         int ct = 0;
30         for (int i=0; i<m; i++) {
31             if (binary_search(nums2, nums2+n, nums1[i]) == true) {
32                 ct++;
33             }
34         }
35         printf("%d\n", ct);
36     }
37     return 0;
38 }

 

posted @ 2018-04-12 21:47  朤尧  阅读(436)  评论(0编辑  收藏  举报