| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
1757这道题到底怎么做?
我用的是搜索,可是不知道哪里错了.请大家帮忙看看:
#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator