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

Julius Canute WA TEST#10 Help please!!! [4] // Problem 1064. Binary Search 26 Sep 2006 21:39
#include<iostream>

using namespace std;


int BinarySearch(int N,int i,int l)
{
  int mid,p,q;
  p = 0;
  q = N-1;
  for(int x=0;x<l;x++)
  {
          mid = (p+q)/2;
          if(mid<i)
          p = mid +1;
          else
          q = mid -1;

  }

  if(mid==i)
  return 1;
  else
  return 0;

}

int main()
{
int j,k=0,f,com,flag=0,first,second;
cin>>f>>com;
for(j=f+1;j<=10000;j=j+1)
{
flag = BinarySearch(j,f,com);
   if(flag==1)
   {
   first =j;
   j = j + 1;
    while(BinarySearch(j,f,com)==1)
    {j=j+1;}
   second = j-1;
   k++;
   flag=0;
}
}
cout<<k<<"\n";
for(j=f+1;j<=10000;j=j+1)
{
flag = BinarySearch(j,f,com);
   if(flag==1)
   {
   first =j;
   j = j + 1;
    while(BinarySearch(j,f,com)==1)
    {j=j+1;}
   second = j-1;
   cout<<first<<" "<<second<<"\n";
   flag=0;
}
}


return 0;
}
Julius Canute Re: WA TEST#10 Help please!!! [3] // Problem 1064. Binary Search 28 Sep 2006 07:46
Are These Output correct for given inputs?
100 5

104 104
111 112
119 120
129 129
141 141
154 154
171 172
190 190
215 216
249 250
295 298
359 362
463 466
647 654
1079 1086
3231 3262

56 3

4
65 65
91 92
151 154
455 462
if they are correct,then why my soution is not accepted?
Alex Fetisov Re: WA TEST#10 Help please!!! [2] // Problem 1064. Binary Search 28 Sep 2006 15:15
Try this
0 5
The right answer is
1
31 62
And your answer is
1
1 62
Good Luck! )
Julius Canute Re: WA TEST#10 Help please!!! [1] // Problem 1064. Binary Search 29 Sep 2006 18:07
I modified the code but still failing at Test#16
#include<iostream>

using namespace std;


int BinarySearch(int N,int i,int l)
{
int mid,p,q,x;
  p = 0;
  q = N-1;
  if(N==0)
  x=1;
  else
  x=0;
  for(;(x<l);x++)
  {
          mid = (p+q)/2;

          if(mid==0)break;
          if(mid<i)
          p = mid +1;
          else
          q = mid -1;

  }

  if((x+1)>=l)
  {
  if(mid==i)
  return 1;
  else
  return 0;
  }
  else
  return 0;

}

int main()
{
int j,k=0,f,com,flag=0,first,second;
cin>>f>>com;
for(j=f+1;j<=10000;j=j+1)
{
flag = BinarySearch(j,f,com);
if(flag==1)
{
first =j;
j = j + 1;
while(BinarySearch(j,f,com)==1&&(j<=10000))
{j=j+1;}
second = j-1;
k++;
flag=0;
}
}
cout<<k<<"\n";
for(j=f+1;j<=10000;j=j+1)
{
flag = BinarySearch(j,f,com);
if(flag==1)
{
first =j;
j = j + 1;
while(BinarySearch(j,f,com)==1&&(j<=10000))
{j=j+1;}
second = j-1;
cout<<first<<" "<<second<<"\n";
flag=0;
}
}


return 0;
}
Ermishin Fedor Re: WA TEST#10 Help please!!! // Problem 1064. Binary Search 29 Sep 2006 19:27


Edited by author 29.09.2006 19:31