C - Fight the Monster(暴力)

來源:互聯網
上載者:User

標籤:

題意就不說了

思路:要分析好對什麼進行枚舉,如果對血量也進行枚舉的話,至少要枚舉到10^4,加上對攻擊力和防禦力進行枚舉10^2 * 10^2,可能會TLE。

因為monster的血量是固定的,所以可以通過對攻擊力和防禦力枚舉,求出最少需要的攻擊次數,和這個攻擊次數下保證的血量,每次比較取max即可。。。

 1 #include<iostream> 2 #include<cstdio> 3 #include<cstdlib> 4 #include<cstring> 5 #include<string> 6 #include<queue> 7 #include<algorithm> 8 #include<map> 9 #include<iomanip>10 #include<climits>11 #include<string.h>12 #include<numeric>13 #include<cmath>14 #include<stdlib.h>15 #include<vector>16 #include<stack>17 #include<set>18 #define FOR(x, b, e)  for(int x=b;x<=(e);x++)19 #define REP(x, n)     for(int x=0;x<(n);x++)20 #define INF 1e721 #define MAXN 10001022 #define maxn 100001023 #define Mod 100000724 #define N 101025 using namespace std;26 typedef long long LL;27 28 29 int main()30 {31     int mh, ma, md;32     int yh, ya, yd;33     int h, y, d;34     cin >> yh >> ya >> yd;35     cin >> mh >> ma >> md;36     cin >> h >> y >> d;37     int ans = 1 << 29, r, k;38     for (int i = ya;i <= 200;++ i) //枚舉yang的攻擊力39         for (int j = yd;j <= 100;++ j)//枚舉yang的防禦力40             {41                 if (i <= md) continue;42                 r = ceil((double)mh/(i - md));//yang最少的攻擊次數43                 k = max((ma - j)*r + 1, yh);//yang需要的最少血量44                 ans = min(ans, (k-yh)*h + (i-ya)*y + (j-yd)*d);45             }46     cout << ans << endl;47     return 0;48 }

 

C - Fight the Monster(暴力)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.