ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1064. Binary Search

WHY WA ON TEST#4
Posted by 6yxa/\bl 31 Mar 2007 08:23
Help me please!!!
Give me test #4 please!!!!
This is my code


#include <stdio.h>
int n,m,a[10000];
bool BS(int x)
{
  int p,q,i,L;
  p=0;
  q=x-1;
  L=0;
  while (p<=q)
  {
    i=(p+q)/2;
    ++L;
    if (i==n) return (L==m);
    if (n<i) q=i-1; else p=i+1;
  }
  return (L==m)&&(i==n);
}
int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    int i,j,k,l,r,e=0,u=0;
    scanf("%d%d",&n,&m);
    for(i=1;i<=10000;i++)
    {
        if (BS(i))
        {
            if (i-e>1)
            {
                a[++u]=e;
                a[++u]=i;
            }
            e=i;
        }
    }
    a[++u]=e;
    printf("%d\n",u/2);
    for(i=1;i<=u/2;i++)
    {
        printf("%d %d\n",a[2*i],a[2*i+1]);
    }
    return 0;
}

Edited by author 31.03.2007 08:25