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

1757

Posted by WXuan at 2008-04-26 20:41:00
这道题到底怎么做?
我用的是搜索,可是不知道哪里错了.请大家帮忙看看:
#include<stdio.h>
#include<stdlib.h> 

#define MAXN 10005

int A[MAXN],R[10005][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
	    return false;
}

int main()
{
	int i,l,n,k,j;
	for(j=0;j<MAXN;j++)
		A[j]=j; 
	scanf("%d%d",&i,&l); 
	k=0;
	for(n=1;n<=10000;n++)
	{
	    if(BinarySearch(i,n,l))
		{
	        k++;
	        R[k][0]=n;
	        n++;
	        while(BinarySearch(i,n,l))
				n++;
	        R[k][1]=n-1;    
	    }     
	}
	if(k==0)
		printf("0\n");
	else
	{ 
	    printf("%d\n",k);
	    for(j=1;j<=k;j++)
			printf("%d %d\n",R[j][0],R[j][1]);
	}         
    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