Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:这题需要注意什么,怎么总是WA?

Posted by tkchenhetian at 2007-09-27 13:16:31 on Problem 1757
In Reply To:这题需要注意什么,怎么总是WA? Posted by:lololo at 2005-12-31 19:25:08
> 帮忙看一看吧!
> 
> #include<stdio.h>
> #include<stdlib.h> 
> 
> #define MAXN 10010 
> 
> int A[MAXN],R[10000][2];
> 
> bool BinarySearch(int x,int N,int l)
> {
>   int p, q, i, L;
> 
>   p = 0;   /* Left border of the search  */
>   q = N-1; /* Right border of the search */
>   L = 0;   /* Comparison counter         */
>   while (p <= q) {
>      i = (p + q) / 2;
>      ++L;
>      if(A[i]==x)break; 
>      if (x < A[i])
>         q = i - 1;
>      else
>         p = i + 1;
>     }
>     if(p<=q){
>         if(L==l)return true;
>         else return false; 
>     }
>     else{
>         ++L;
>         if(L==l&&A[N-1]==x)return true;
>         else return false; 
>     }         
> }
> 
> int main(){
>     int n,l,i,k=0;
>     for(i=0;i<MAXN;i++)A[i]=i; 
>     scanf("%d%d",&n,&l); 
>     for(i=1;i<=10000;i++){
>         if(BinarySearch(n,i,l)){
>             k++;
>             R[k][0]=i;
>             while(BinarySearch(n,i,l))i++;
>             R[k][1]=i-1;    
>         }     
>     }
>     if(!k)printf("0\n");
>     else{ 
>         printf("%d\n",k); 
>         for(i=1;i<=k;i++)printf("%d %d\n",R[i][0],R[i][1]);
>     }    
>     system("pause");     
>     return 0; 
> }

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator