Posted on 2008-12-13 16:58
Hero 阅读(109)
评论(0) 编辑 收藏 引用 所属分类:
代码如诗--ACM
1 // 1196 C++ Accepted 0.203 181 KB URAL
2
3 //简单二分
4
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8
9 int data[15100] ;
10
11 int inn, inm ;
12
13 bool binfind( int x )
14 {
15 int left = 1 ; int right = inn ; int mid ;
16 while( left <= right )
17 {
18 mid = ( left + right ) >> 1 ;
19 if( data[mid] == x ) return true ;
20 else if( data[mid] < x ) left = mid + 1 ;
21 else right = mid - 1 ;
22 }
23
24 return false ;
25 }
26
27 int main()
28 {
29 while( scanf( "%d", &inn ) != EOF )
30 {
31 for( int i=1; i<=inn; i++ )
32 {
33 scanf( "%d", &data[i] ) ;
34 if( data[i] == data[i-1] ) { i-- ; inn--; }
35 }
36
37 scanf( "%d", &inm ) ; int out = 0 ; int year ;
38 for( int i=1; i<=inm; i++ )
39 {
40 scanf( "%d", &year ) ;
41 if( binfind( year ) ) out++ ;
42 }
43
44 printf( "%d\n", out ) ;
45 }
46 return 0 ;
47 }