Tuesday, July 05, 2011

[UVa] 11247 - Income Tax Hazard

Simplification of the theorem solves the problem with a few glitches to overlook.
First of all v-(vx)/100 < m-1. Let q = m-1. Play with it for a while and you get => v < q/(100-x)/100 => v < 100q / (100-x) Don't ignore the < sign it will drag you by the nose for a while. So you generate a v from this. But realize if 100q is completely dividable by (100-x) then v must be smaller. So check if that happens. If it does, just decrease v by 1. And some other gotchas are x being m being 1 because you use m-1 and x being 0 or 100.


#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <iostream>
using namespace std;

int main()
{
long long v, p, q;
long long m, x, orig_m;
while (cin >> m >> x)
{
if (!m && !x)
return 0;

if (m==1 || x==0 || x==100)
{
printf("Not found\n");
continue;
}

v = (100*(m-1)) / (100-x);

if (( (100*(m-1)) % (100-x) ) == 0)
v--;

if (v<m)
{
printf("Not found\n");

} else
{
cout << v << endl;
}
}
return 0;
}

No comments:

Post a Comment

Post your comment here. If you want to say something about programming problems, scripts, software etc, please try to be as descriptive as possible.

Connect Rapoo MT750S with Linux (Tested on Manjaro)

 I bought this obvious copy of MX Master 2S in hopes of having the device switching functionality along with a lightweight body because I ha...