## 11247 - Income Tax

Moderator: Board moderators

t.tahasin
New poster
Posts: 38
Joined: Tue May 28, 2013 11:21 pm

### Re: 11247 - Income Tax Hazard

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.

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)
{
else
{
long long min = m-1;
double deduct = ((double)rate/100.0)*(double)m;
long long x = m - deduct;
if(x>=min)
{
}
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);
}
}
}

``````

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 11247 - Income Tax Hazard

Try solving it without using floating point.
Check input and AC output for thousands of problems on uDebug!

New poster
Posts: 5
Joined: Mon May 12, 2014 10:10 am

### Re: 11247 - Income Tax Hazard

Hello, i keep getting WA in this problem
I tried all the suggestions in this thread (no floats, m - 1 > v*(100-x)/100, etc.) but still i keep getting WA. Edit: Finally figured it out. Thanks for the help brianfry Code: Select all

``````//Removed after AC
``````
Last edited by lolicaddict on Thu Jul 31, 2014 1:38 pm, edited 1 time in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 11247 - Income Tax Hazard

Input:

Code: Select all

``````627326930 1
0 0
``````
AC output:

Code: Select all

``````633663564
``````
Check input and AC output for thousands of problems on uDebug!

New poster
Posts: 5
Joined: Mon May 12, 2014 10:10 am

### Re: 11247 - Income Tax Hazard

Thanks for the test input! I was finally able to correct my mistake )

ssavi
New poster
Posts: 28
Joined: Thu Nov 20, 2014 9:57 pm

### Re: 11247 - Income Tax

I found a formula for this problem is

Code: Select all

``[ A = (M*100)/(100-X) ]``
which is Adjacent to the result.
But the result in the test case will come accurately after subtracting 1 from M i.e.

Code: Select all

`` [ A = ((M-1)*100)/(100-Z) ]``
Why????
Why I Have To Subtract 1 from M ?? Someone ans the reason .
I know I am a Failure Guy . 