Skip to content

Instantly share code, notes, and snippets.

@fpdjsns
Last active February 17, 2019 10:53
Show Gist options
  • Save fpdjsns/d99f5b1133b142fb8d505c367fcee702 to your computer and use it in GitHub Desktop.
Save fpdjsns/d99f5b1133b142fb8d505c367fcee702 to your computer and use it in GitHub Desktop.
[Round 1A 2017] Problem C. Play the Dragon (SMALL) : https://code.google.com/codejam/contest/5304486/dashboard#s=p2&a=2
//
// Created by fpdjsns
// Copyright © 2019 fpdjsns. All rights reserved.
//
/*
* 시간복잡도 : O(N^3)
*/
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#define MAX 1e9
using namespace std;
int Hd, Ad, Hk, Ak, B, D;
int getTurn(int buff, int debuff) {
int turn = 0;
// Debuff
int newAk = Ak;
int myHeal = Hd;
for (int i = 0; i < debuff; i++) {
if (myHeal - (newAk - D) <= 0) { // need heal
turn++;
myHeal = Hd - newAk;
}
newAk -= D;
myHeal -= newAk;
turn++;
if (myHeal <= 0) return MAX;
}
// Buff
int newAd = Ad;
for (int i = 0; i < buff; i++) {
if (myHeal - newAk <= 0) { //need heal
turn++;
myHeal = Hd - newAk;
}
myHeal -= newAk;
turn++;
newAd += B;
if (myHeal <= 0) return MAX;
}
// count Attack
// return ceil((double)Hk / newAd) + turn;// need heal count
int knightH = Hk;
while (0 < knightH) {
if (myHeal - newAk <= 0 && newAd < knightH) { //need heal
turn++;
myHeal = Hd - newAk;
}
knightH -= newAd;
myHeal -= newAk;
turn++;
if (myHeal <= 0 && 0 < knightH) return MAX;
}
return turn;
}
int main() {
int t;
cin >> t;
for (int c = 1; c <= t; c++) {
int answer = MAX;
cin >> Hd >> Ad >> Hk >> Ak >> B >> D;
printf("Case #%d: ", c);
// set Buff
for (int i = 0; i <= 100; i++) {
// set Debuff
for (int j = 0; j <= 100; j++) {
answer = min(answer, getTurn(i, j));
if (D == 0) break;
}
if (B == 0) break;
}
if (answer == MAX) {
printf("IMPOSSIBLE\n");
}
else {
printf("%d\n", answer);
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment