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 1011. Conductors

Why WA#5?
Posted by Abhay 4 Dec 2005 14:37
The follwing is my pgm. Could some give a test case not satisfied here?
#include<iostream.h>
#include<math.h>
int main()
{
float p,q,a,b;
int x,a1,b1;
cin>>p>>q;
p/=100;
q/=100;
for(x=1;x<=10000;x++)
{
a=p*x;
b=q*x;
a1=a;
b1=b;
if((float)b1==b)
b1++;
if((float)a1==a)
a1--;
if(abs(b1-a1)==1)break;
}
cout<<x;
return 0;
}
Re: Why WA#5?
Posted by hardfire 25 Feb 2007 19:55
The dude, at me too the fifth test does not go, but if it is interesting to you here my idea and algorithm
My solve
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
#ifndef ONLINE_JUDGE
freopen("1011.in","r",stdin);
freopen("1011.out","w",stdout);
#endif
double p,q;
cin>>p>>q;
p/=100.;
q/=100.;
int n=1,fr=n*p,to=n*q;
while(ceil(n*q)-ceil(n*p) < 1) n++;
cout<<n;
return 0;
}