CST14-cc's blog

By CST14-cc, 9 years ago, In English

C. Fight the Monster

题目意思就是一个人有初始的hp atk def,蜘蛛也有初始的hp atk def,人物可以买1点属性花费 h a d 的财富,求最小花费。 最开始以为是DP,费了很大的功夫。其实只要枚举攻击大于初始攻击力和防御大于初始防御力的情况,判断是否能打过蜘蛛就OK了。

#include <iostream>

using namespace std;
int hp1,atk1,def1,hp2,atk2,def2,h,a,d;
int dp(int hp,int atk,int def,int h2){
    if(h2<=0 && hp>0)
        return 0;
    hp = hp -max(0,atk2-def);
    int t=0;
    if(hp<=0){
        t = 1-hp;
        hp = 1;
    }
    h2 = h2 - atk +def2;
    return dp(hp,atk,def,h2)+t*h;
}

int main()
{

    cin>>hp1>>atk1>>def1;
    cin>>hp2>>atk2>>def2;
    cin>>h>>a>>d;
    int ans = 0;
    if(atk1<=def2){
        ans = (def2+1-atk1)*a;
        atk1 = def2+1;
    }
    if(def1>=atk2){
        cout<<ans;
        return 0;
    }
    else{
        if(hp1/(atk2-def1) >hp2/(atk1-def2) ){
            cout<<ans;
            return 0;
        }
        else{
            int mm=9999999; int tmin;
            for(int i=atk1;i<=1000;i++){
                for(int j=def1;j<=1000;j++){
                    tmin = dp(hp1,i,j,hp2)+(i-atk1)*a+(j-def1)*d;
                    if(mm>tmin)
                        mm=tmin;
                }
            }
            cout<<mm+ans;
        }
    }

    return 0;
}


  • Vote: I like it
  • -23
  • Vote: I do not like it

»
9 years ago, # |
  Vote: I like it 0 Vote: I do not like it

I can't help you because I don't understand what you want. Write in English please.

  • »
    »
    9 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    You need not to help him. He is just introducing his solution to others.

  • »
    »
    9 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Thank you for your visit.This is my first time to write blog.I'm just write a solution.

    • »
      »
      »
      9 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Unfortunately only English and Russian are official languages of Codeforces. It's strongly recommended to write your blog in English.