Created
May 24, 2016 15:01
-
-
Save macrat/9be0d22fdf1c2d8402e391c147bd02af to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <cmath> | |
| #include <iostream> | |
| int withoutTax(int cost, int tax){ | |
| return std::ceil(cost * 100.0 / (100.0+tax)); | |
| } | |
| int withTax(int cost, int tax){ | |
| return std::floor(cost * (100.0+tax) / 100.0); | |
| } | |
| int changeTax(int cost, int pre, int aft){ | |
| return withTax(withoutTax(cost, pre), aft); | |
| } | |
| /** ある税率の時にありうる金額かどうか調べる。 | |
| * 消費税が9%のときには税込み12円はありえないっぽい。 | |
| * そんな感じの変な価格を踏まないためのチェック。 | |
| */ | |
| bool verify(int cost, int tax){ | |
| return cost == changeTax(cost, tax, tax); | |
| } | |
| int main(){ | |
| while(true){ | |
| int pre, aft, cost; | |
| std::cin >> pre >> aft >> cost; | |
| if(cost == 0){ | |
| break; | |
| } | |
| int max = 0; | |
| for(int shift=1; shift<cost/2; shift++){ | |
| if(verify(shift, pre) && verify(cost - shift, pre)){ | |
| max = std::max(max, changeTax(shift, pre, aft) + changeTax(cost - shift, pre, aft)); | |
| } | |
| } | |
| std::cout << max << std::endl; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment