Two methods set container and two points, do not understand set container look at me this article http://blog.csdn.net/su20145104009/article/details/44562659
#include <stdio.h>//set container Find # include <set>using namespace Std;int main () {int n,m,x,i;set<int>s; scanf ("%d%d", &m,&n), for (i=0;i<m;i++) scanf ("%d", &x), S.insert (x); for (i=0;i<n;i++) {scanf ("%d", &x), if (S.find (x)!=s.end ()) printf ("yes\n"); elseprintf ("no\n");} return 0;}
#include <stdio.h>//two points find # include <string.h> #include <algorithm>using namespace Std;long a[1000005] void search (long X,long right) {long Mid,left=0,flag=0;while (left<=right) {mid= (left+right)/2;if (a[mid]<x) Left=mid+1;if (a[mid]>x) right=mid-1;if (a[mid]==x) {flag=1;printf ("yes\n"); if (!flag) printf ("no\n");} int main () {Long M,n,i,num;memset (a,0,sizeof (a)), scanf ("%ld%ld", &m,&n), for (i=0;i<m;i++) scanf ("%ld", &a[i]); sort (a,a+m); for (i=0;i<n;i++) {scanf ("%ld", &num); search (num,m-1);} return 0;}
Nyoj86 Find the ball number (a) set container and two kinds of solution