fc2ブログ



Ohgas' Fortune

2006.07.04 23:47  ACM/ICPC

[問題]:ACM/ICPC 2005 Problem A

[プログラム例]

// @author yutaka C++
#include<iostream>
#include<algorithm>

using namespace std;

int getTanri( int current, int years, double ratio, int option ){
    int interest = 0;
    for ( int i = 0; i < years; i++ ){
        interest += (int)(current * ratio);
        current -= option;
    }
    return current + interest;
}

int getFukuri( int current, int years, double ratio, int option ){
    for ( int i = 0; i < years; i++ ){
        current += (int)(current * ratio);
        current -= option;
    }
    return current;
}

void work(){
    int current, years, n;
    cin >> current >> years >> n;
    
    int maximum = 0;
    
    int method, option;
    double ratio;
    for ( int i = 0; i < n; i++ ){
        cin >> method >> ratio >> option;
        if ( method == 0 ){
            maximum = max( maximum, getTanri( current, years, ratio, option ));
        } else {
            maximum = max( maximum, getFukuri( current, years, ratio, option ));
        }
    }
    
    cout << maximum << endl;
}

main(){
    int tcase; cin >> tcase;
    for ( int i = 0; i < tcase; i++ ){
        work();
    }
}
スポンサーサイト



テーマ : プログラミング - ジャンル : コンピュータ

| コメント(0) | トラックバック(0) | ↑ページトップ |

この記事へのコメント

コメントを書く


管理人にのみ表示

↑ページトップ

この記事へのトラックバック

この記事にトラックバックする(FC2ブログユーザー)

↑ページトップ