kanetaiの二次記憶装置

プログラミングに関するやってみた、調べた系のものをQitaに移して、それ以外をはてブでやる運用にしようと思います。http://qiita.com/kanetai

Ohgas' Fortune(PKU No.2683)

Ohgas' Fortune(PKU No.2683)

ただの読解問題http://www.deqnotes.net/acmicpc/2683/jaに日本語版がある。
預金して最終残高が最大になるようなオペレーションを選んだときの最終残高を求める。

 運用資金の残高(年始)A 利子B=A×年利率(1円未満切捨て) 運用資金の残高(年末)=A+B-年間手数料
 最終残高は運用資金の残高(最終年末)

  • 単利の場合

 運用資金の残高(年始)A 利子=B=A×年利率(1円未満切捨て) 運用資金の残高(年末)=A-年間手数料
 最終残高は運用資金の残高(最終年末)+利子の累積和

  • Input

 データセット数(=m)
 データセット1の記述
 データセット2の記述
  ...
 データセットmの記述

 初期運用資金
 運用年数
 運用方法の種類数(=n)
 運用方法1の記述
 運用方法2の記述
  ...
 運用方法nの記述

  • 運用方法の記述

 単利(0)・複利(1)の別 年利率 年間手数料

制約
m≦100
初期運用資金量≦100000000
運用年数≦10
n≦100
0≦年間手数料≦100000
最終残高は1000000000を超えることはない

import java.util.Scanner;

public class pku2683 {
	static Scanner stdin;
	public static void main(String[] args) {
		stdin = new Scanner(System.in);
		new pku2683();
	}
	
	int compound(int A, int year, double rate, int charge){
		while(year-- > 0){
			A = A + (int)(A*rate) - charge;
		}
		return A;
	}
	int simple(int A, int year, double rate, int charge){
		int cumulative = 0;
		while(year-- > 0){
			cumulative += (int)(A*rate);
			A -= charge;
		}
		return (cumulative + A);
	}
	
	pku2683(){
		int m = stdin.nextInt();
		while ( m-- > 0 ){
			int max = 0;
			int A = stdin.nextInt();
			int y = stdin.nextInt();
			int n = stdin.nextInt();
			while ( n-- > 0 ){
				int method = stdin.nextInt();
				double r = stdin.nextDouble();
				int c = stdin.nextInt();
				int interest = (method == 0 ? simple(A, y, r, c) : compound(A, y, r, c) );
				if(max < interest) max = interest;
			}
			System.out.println(max);
		}
	}
}