AOJ-1192 : Tax Rate Changed
Tax Rate Changed | Aizu Online Judge
税込合計価格が同じだった2商品の組が,消費税率の変更後に異なる税込合計価格になりうる。
2つの商品の消費税率変更前の税込合計価格を元に, 新消費税率での税込合計価格が最大いくらになるかを計算する。
2商品の組み合わせなので、2重ループで全探索することが出来る。
sの値が最大1000までなので、全探索してもまったく問題なし。
落とし穴としては、下手にdoubleなどを使って計算すると誤差で死ぬ。
税抜価格が p 円である商品の税込価格は, p (100+x) / 100 円を小数点以下切り捨てたものである.
小数点以下を切り捨てるため、int型で計算する事で誤差を気にせず計算出来る。
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1192&lang=jp #include<iostream> #include<map> #include<vector> #include<algorithm> #include<cmath> #include<climits> #include<ctime> #include<cstring> #include<numeric> #define ALL(v) (v).begin(),(v).end() #define REP(i,p,n) for(int i=p;i<(int)(n);++i) #define rep(i,n) REP(i,0,n) #define dump(a) (cerr << #a << "=" << (a) << endl) #define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl; using namespace std; int calc(int p, int x){ return p*(100+x)/100; } int main() { int X,Y,S; while(cin >> X >> Y >> S && X) { int ans=0; REP( y, 1, S ){ REP( x, 1, S ){ if(calc(x,X)+calc(y,X) == S){ int x2 = calc(x,Y); int y2 = calc(y,Y); ans = max(x2+y2,ans); } } } cout << ans << endl; } return 0; }