|
|
back to boardWA Posted by shouu 28 Jul 2015 07:37 给二分查找的参数传错了,传的是m。 弄得我都快崩溃了。 不过还好看了解答发现了。 下面是C代码 ********************************************************************************************** #include<stdio.h> int teacher[15001]={0}; int exist_temp(int temp,int m){ int first=0,last=m-1,count=0; while(first<=last){ int mid=(first+last)/2; if(teacher[mid]==temp){ count++; return count; } else{ if(teacher[mid]>temp) last=mid-1; else first=mid+1; } } return count; } int main(){ int n,m,i; scanf("%d",&n); for(i=0;i<n;i++) scanf("%d",&teacher[i]); scanf("%d",&m); int count=0,hi=m; while(hi--){ int temp; scanf("%d",&temp); if(exist_temp(temp,n)!=0) count++; } printf("%d\n",count); return 0; } |
|
|