bacon_egg @ ウィキ

コリンク-Ohgas' Fortune

最終更新:

匿名ユーザー

- view
だれでも歓迎! 編集
/*
Problem A: Ohgas' Fortune
制作時間:2010/4/24 20:31~2010/4/24 21:00 (29分)
作者:コリンク

[解き方]
まず INPUT の書式に合わせて入力インタフェースから作る。
入力に使った変数のおかげで問題文をより理解しやすくなり、書かれている通りの処理を記述。
最後に出力を記述、といった感じ。
*/

#include <cstdio>
#define	outstr(s)	fputs(s, stderr);

template <typename T>
T chooseMax(T a, T b){
	return (a > b) ? a : b;
}

int main(int argc, char *argv[]){
	/* 入力の変数 */
	int m;
	int shokiunyou, unyounen, n;
	int input;
	bool fukuri;
	double nenriritsu;
	int tesuuryo;

	/* 出力の変数 */
	int i, j;
	int max;

	/* 制御変数 */
	int zandaka, rishi;

	scanf("%d", &m);

	for(; m > 0; --m){
		scanf("%d", &shokiunyou);
		scanf("%d", &unyounen);
		scanf("%d", &n);
		max = 0;
		for(; n > 0; --n){
			/* 入力 */
			scanf("%d %lf %d", &input, &nenriritsu, &tesuuryo);
			fukuri = input > 0;

			/* 処理 */
			zandaka = shokiunyou;
			rishi = 0;
			for(i = 0; i < unyounen; ++i){
				rishi += (int)(nenriritsu * (double)zandaka);
				if(fukuri){
					zandaka += rishi - tesuuryo;
					rishi = 0;
				}else{
					zandaka -= tesuuryo;
				}
			}
			if(!fukuri){
				zandaka += rishi;
			}
			max = chooseMax(zandaka, max);
		}

		printf("%d\n", max);
	}

	return 0;
}

タグ:

+ タグ編集
  • タグ:

このサイトはreCAPTCHAによって保護されており、Googleの プライバシーポリシー利用規約 が適用されます。

記事メニュー
目安箱バナー