中南月赛F ZZY and his little friends

Problem F: ZZY and his little friends

Time Limit: 5 Sec  Memory Limit: 256 MB
Submit: 137  Solved: 70
[Submit][Status][Web Board]

Description

  zzy养了一只小怪兽和N只凹凸曼,单挑的话每只凹凸曼都不是小怪兽的对手,所以必须由两只凹凸曼合作来和小怪兽战斗。凹凸曼A和凹凸曼B合作的战斗力为他们战斗力的异或值。现在由zzy从N只凹凸曼中选出两只来和小怪兽战斗。请问zzy能否选出两只凹凸曼使他们能够战胜小怪兽(他们的战斗力比小怪兽大)。

Input

  输入有多个例子,直到文件结束。 每个例子的第一行含两个数N和M,表示有N(2<=N<=100000)只凹凸曼,小怪兽的战斗力为M(0<M<=1000000000)。接着有一行N个数,每个数Ai(0<Ai<M)表示每只凹凸曼的战斗力。

Output

  对于每个例子输出一行,如果能选出两只凹凸曼使他们战胜小怪兽输出"YES", 否则输出"NO"(不含引号)

Sample Input

2 5
1 1
2 6
5 2

Sample Output

NO
YES

HINT

 CSU_CX

 

直接暴力过的。不是标程方法。

 1 #include<iostream> 
 2 #include<cstdio> 
 3 #include<cstring> 
 4 #include<cstdlib> 
 5 using namespace std; 
 6   
 7 int f[100003]; 
 8 int main() 
 9 { 
10     int n,m,flag; 
11     int i,j; 
12     while(scanf("%d%d",&n,&m)>0) 
13     { 
14   
15         for(i=1;i<=n;i++) 
16             scanf("%d",&f[i]); 
17         flag=0; 
18         for(i=1;i<=n;i++) 
19         { 
20             for(j=1;j<=n;j++) 
21             { 
22                 if((f[i]^f[j])>m) 
23                 { 
24                     flag=1; 
25                     break; 
26                 } 
27             } 
28             if(flag==1)break; 
29         } 
30         if(flag==1) printf("YES\n"); 
31         else printf("NO\n"); 
32     } 
33     return 0; 
34 } 

 

posted @ 2013-10-02 16:42  芷水  阅读(332)  评论(0编辑  收藏  举报