Posted on 2008-08-01 02:16
Hero 阅读(127)
评论(0) 编辑 收藏 引用 所属分类:
代码如诗--ACM
/*
ID: wangzha4
LANG: C++
TASK: URAL1021
*/
//JUDGE_ID: 65448BI
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define llong unsigned long long
#define unint unsigned int
#define printcrlf printf( "\n" )
const int INF = 10000 ;
const int size = 500010 ;
int inm, inn ;
int data1[size] ;
int data2[size] ;
int mybsearch( int key, int *arry, int num )
{
int left = 1; int right = num ;
while( left <= right ) {
int mid = ( left + right ) / 2 ;
if( key == arry[mid] ) return mid ;
else if( key > arry[mid] ) left = mid + 1 ;
else if( key < arry[mid] ) right = mid - 1 ;
}
return 0 ;
}
int cmp( const void *a, const void *b )
{
return -( *(int *)a - *(int *)b );//注意这里是降序排列
}
int main()
{
//freopen( "frac1.in", "r", stdin ) ;
//freopen( "frac1.out","w",stdout ) ;
while( scanf( "%d",&inn ) != EOF )
{
for( int i=1; i<=inn; i++ ) {
scanf( "%d",&data1[i] ) ;
data1[i] = INF - data1[i] ;
}
scanf( "%d",&inm ) ; bool OK = false ;
for( int i=1; i<=inm; i++ ) {
scanf( "%d",&data2[i] ) ;
//data2[i] = INF - data2[i] ;
}
for( int i=1; i<=inn; i++ ) {
if( NULL != bsearch( &data1[i], data2+1, inm, sizeof(int), cmp ) ) {
OK = true ; break ;
}
}
if( OK ) printf( "YES\n" ) ;
else printf( "NO\n" ) ;
}//while
return 0 ;
}