Idea:FP7317
solution
Problem Description
You are tasked with finding the minimum number of bandages required to defeat a dragon using a sword. The sword deals:
- 1 damage if the i-th attack is not divisible by 3.
- 2 damage if the i-th attack is divisible by 3.
If your health becomes less than 0 at any point, you must use a bandage to restore it.
Solution Approach
You can solve this problem using a while
loop to determine the minimum number of bandages required.
code(C++)
void solve(){
int h,k,n;cin>>h>>k>>n;
int ans = 0, l = k, r = 1;
while(h > 1){
r++;
k -= n;
if(k <= 0){
k = l - n;
ans++;
}
if(r % 3 == 0){
h-=2;
}else{
h--;
}
}
cout<<ans<<endl;
}
Idea:reyleigh
solution
code(C++)
Idea:pramod_17
solution
code(C++)
Idea:sanju77
solution
code(C++)
Idea:wuhudsm
tags
solution
Idea:pramod_17
solution
code(C++)