Codeforces 488 C.Fight the Monster(シミュレーション)

1620 ワード

Fight the Monster
テーマリンク:
http://codeforces.com/problemset/problem/488/C
問題解決の考え方:
Codeforces公式テーマ:
It isのuse to make Yang's ATK>HP_M+DEF_M(Yang already can beat it in a second).And it'sのuse to make Yang's DEF'ATK_M(it cannot deal any damage to him)
As a result,Yang's final ATK will not exceed 200,and final DEF will not exceed 100.So just enumerate final ATK from ATK_Y to 200,final DEF from DEF_Y to 100.
With final ATK and DEF known,you can can caculate how long the battle will last,then caculate HP loss.You can easure find the gold You spend,and the n find the optimal answer.
題名データ量が小さいので、直接列挙して暴力すれば答えが出ます。(All numbers in inputar) インテグ and lie between 1 and 100 inclusively.)
ACコード:
#include <iostream>
#include <cstdio>
#define INF 0xfffffff
using namespace std;
int main(){
    int hy,ay,dy;
    int hm,am,dm;
    int h,a,d;
    while(scanf("%d%d%d",&hy,&ay,&dy)!=EOF){
        scanf("%d%d%d",&hm,&am,&dm);
        scanf("%d%d%d",&h,&a,&d);
        int i,j,k,ans=INF;
        for(i = 0; i <= 200; i++) //  
            for(j = 0; j <= 200; j++) //  
                for(k = 0; k <= 1000; k++){//  
                    if(ay+i <= dm)
                        continue;
                    int t = (hm-1)/(ay+i-dm)+1;//     
                    if(k <= t*(am-dy-j)-hy)
                        continue;
                    ans = min(ans,h*k+a*i+d*j);
                }
        printf("%d
",ans); } return 0; }