Page 4 of 4

Re: 11247 - Income Tax Hazard

Posted: Tue Jun 25, 2013 7:40 pm
by t.tahasin
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)
	{
		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);
		}
	}
}


Re: 11247 - Income Tax Hazard

Posted: Tue Jun 25, 2013 11:40 pm
by brianfry713
Try solving it without using floating point.

Re: 11247 - Income Tax Hazard

Posted: Wed Jul 30, 2014 10:00 am
by lolicaddict
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. :cry:
Edit: Finally figured it out. Thanks for the help brianfry :D

Code: Select all

//Removed after AC

Re: 11247 - Income Tax Hazard

Posted: Wed Jul 30, 2014 8:00 pm
by brianfry713
Input:

Code: Select all

627326930 1
0 0
AC output:

Code: Select all

633663564

Re: 11247 - Income Tax Hazard

Posted: Thu Jul 31, 2014 1:37 pm
by lolicaddict
Thanks for the test input! I was finally able to correct my mistake :))

Re: 11247 - Income Tax

Posted: Tue Jun 09, 2015 8:42 pm
by ssavi
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 .