Codeforces Round #278 (Div. 2) C. Fight the Monster 二分+枚举
来源:互联网 发布:淘宝美工和网页设计 编辑:程序博客网 时间:2024/05/20 18:52
二分所需的花费,对给定花费枚举hp、atk、def的购买数量。
代码如下
#include <cstdio>using namespace std;#define INF 30100#define max(a, b) (a) > (b) ? (a) : (b)int hp[2], atk[2], def[2];int h, a, d;bool check(int x){int bound_hp = x / h, rest = x;bool found = false;for(int i = 0; i <= bound_hp && !found; ++i){int bound_atk = rest / a, rest_d = rest, new_hp = hp[0] + i;for(int j = 0; j <= bound_atk && !found; ++j){int new_atk = atk[0] + j;int new_def = def[0] + rest_d / d;rest_d -= a;int dec_y = max(0, atk[1] - new_def), dec_m = max(0, new_atk - def[1]);if(dec_m == 0)continue;else if(dec_y == 0)found = true;else{int time = hp[1] % dec_m ? hp[1] / dec_m + 1 : hp[1] / dec_m;if(dec_y * time < new_hp)found = true;}}rest -= h;}return found;}int main(){scanf("%d %d %d", &hp[0], &atk[0], &def[0]);scanf("%d %d %d", &hp[1], &atk[1], &def[1]);scanf("%d %d %d", &h, &a, &d);int l = 0, r = INF;while(l < r){int mid = l + ((r - l) >> 1);if(check(mid))r = mid;elsel = mid + 1;}printf("%d\n", l);return 0;}
0 0
- Codeforces Round #278 (Div. 2) C. Fight the Monster 二分+枚举
- Codeforces Round #278 (Div. 2) 488C.Fight the Monster
- Codeforces Round #278 (Div. 2) C. Fight the Monster(暴力)
- Codeforces 488C Fight the Monster【二分+枚举】
- codeforces 488C Fight the Monster(枚举)
- CodeForces 488 C.Fight the Monster(枚举)
- Codeforces Round #278 (Div. 1) A. Fight the Monster( 暴力)
- codeforces #487A# Fight the Monster(枚举)
- codeforces 487 A Fight the Monster 暴力枚举
- CF_487A Fight the Monster(二分)
- Codeforces 488 C. Fight the Monster(模拟)
- codeforces 487A Fight the Monster
- 【Codeforces】 487A Fight the Monster
- CodeForces 487A Fight the Monster
- Codeforces 487A Fight the Monster(暴力)
- Codeforces 487A Fight the Monster
- Codeforces Round #328 (Div. 2)_B. The Monster and the Squirrel
- Codeforces Round #328 (Div. 2) B. The Monster and the Squirrel(数学规律)
- liunx连接不上外网
- 路由器怎么设置无线上网
- *LeetCode:Longest Palindromic Substring
- nil,Nil,NULL,NSNull
- iOS视频播放界面显示音量调节控件
- Codeforces Round #278 (Div. 2) C. Fight the Monster 二分+枚举
- Splay树(区间第k小)——POJ 2761 Feed the dogs
- UVA - 489 - Hangman Judge
- 有项目管理模板提供吗?(模板和管理工具对过程改进的帮助)
- 记录手机app的使用时长
- 找不到匹配的outgoing encryption算法(No matching outgoing encryption algorithm found)
- Android 网络层的封装
- RuntimeException
- 黑马程序员_java反射