标签:style blog http io color ar sp for div
题解报告:一道典型的二分查找题,用C++做居然超时>1000MS,郁闷半天!,该成C,提交680MS过,C还是很快的!
#include <stdio.h> #include <stdlib.h> int a[1010][1010]; int main() { int m, n, t; int flag; while(scanf("%d%d", &m, &n) !=EOF){ scanf("%d", &t); for(int i=0; i<m; i++) for(int j=0; j<n; j++) scanf("%d", &a[i][j]); for(int i=0; i<m; i++){ flag = 1; //if(!binary_Search(a[i], 0, n-1, t)) // { /// flag = 0; // break; // } int left=0, right=n-1; while(left <= right){ int mid = (left+right)>>1; if(a[i][mid] > t){ right = mid - 1; }else if(a[i][mid] < t){ left = mid + 1; }else{ flag=0; break; } } if(!flag) break; } if(!flag) printf("Yes\n"); else printf("No\n"); } return 0; } /************************************************************** Problem: 1384 User: qiu0130 Language: C Result: Accepted Time:680 ms Memory:4900 kb ****************************************************************/
标签:style blog http io color ar sp for div
原文地址:http://www.cnblogs.com/qiu0130/p/4084700.html