Re: 11247 - Income Tax Hazard
Posted: Tue Jun 25, 2013 7:40 pm
I am getting WA all the time. I tried with all the input from this thread and found my program is OK. but still WA. Can anyone help me please.
here is my code.
here is my code.
Code: Select all
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <string>
#include <list>
#include <vector>
#include <map>
using namespace std;
long long BinarySearch(long long low, long long high, long long val, long long rate)
{
if(high<=low) return low;
long long mid = (low+high)/2;
long long x = mid - ((double)rate/100)*(double)mid;
if(x<=val) return BinarySearch(mid+1, high, val, rate);
else return BinarySearch(low, mid-1, val, rate);
}
int main()
{
long long m, rate;
while(scanf("%lld %lld",&m,&rate) && m)
{
if(!rate || rate == 100LL) printf("Not found\n");
else
{
long long min = m-1;
double deduct = ((double)rate/100.0)*(double)m;
long long x = m - deduct;
if(x>=min)
{
printf("Not found\n"); continue;
}
m += deduct;
x = m - ((double)rate/100)*(double)m;
while(x<=min)
{
m += deduct;
x = m - ((double)rate/100.0)*(double)m;
}
m = BinarySearch(m-deduct, m, min, rate);
x = m - ((double)rate/100)*(double)m;
while(x<min)
{
m++;
x = m - ((double)rate/100.0)*(double)m;
}
while(x>=min)
{
m--;
x = m - ((double)rate/100.0)*(double)m;
}
printf("%lld\n",m);
}
}
}