11247 - Income Tax

All about problems in Volume 112. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

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

Re: 11247 - Income Tax Hazard

Post by t.tahasin » 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.

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);
		}
	}
}


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

Re: 11247 - Income Tax Hazard

Post by brianfry713 » Tue Jun 25, 2013 11:40 pm

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

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

Re: 11247 - Income Tax Hazard

Post by lolicaddict » Wed Jul 30, 2014 10:00 am

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
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

Post by brianfry713 » Wed Jul 30, 2014 8:00 pm

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!

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

Re: 11247 - Income Tax Hazard

Post by lolicaddict » Thu Jul 31, 2014 1:37 pm

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

Post by ssavi » Tue Jun 09, 2015 8:42 pm

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 . :(

Post Reply

Return to “Volume 112 (11200-11299)”