PDD13. 回合制游戏
描述
你在玩一个回合制角色扮演的游戏。现在你在准备一个策略,以便在最短的回合内击败敌方角色。在战斗开始时,敌人拥有HP格血量。当血量小于等于0时,敌人死去。一个缺乏经验的玩家可能简单地尝试每个回合都攻击。但是你知道辅助技能的重要性。输入描述
第一行是一个数字HP输出描述
输出一个数字表示最小回合数示例1
输入:
13 3 5
输出:
5
C 解法, 执行用时: 2ms, 内存消耗: 340KB, 提交时间: 2021-10-19
#include <stdio.h> int main() { int HP, normalAttack, buffedAttack; int count = 0; scanf("%d\n%d\n%d", &HP, &normalAttack, &buffedAttack); if(HP < normalAttack) count = 1; else if(HP < buffedAttack) count = 2; else if(2*normalAttack >= buffedAttack) { count = HP/normalAttack; if(HP%normalAttack) count++; } else { count = HP/buffedAttack*2; int rem = HP%buffedAttack; if(rem != 0 && rem <= normalAttack) count++; else if(rem > normalAttack) count+=2; } printf("%d", count); return 0; }
C 解法, 执行用时: 2ms, 内存消耗: 372KB, 提交时间: 2021-10-07
#include<stdio.h> int up(int n, int m) { if(n % m == 0) { return n/m; } else { return n/m + 1; } } int main() { int hp,normalAttack,buffedAttack; scanf("%d",&hp); scanf("%d",&normalAttack); scanf("%d",&buffedAttack); if(normalAttack * 2 >= buffedAttack) { printf("%d",up(hp,normalAttack)); } else { int temp = hp % buffedAttack; if(temp <= normalAttack && temp != 0) { printf("%d",2*hp/buffedAttack+1); } else { printf("%d",2*up(hp,buffedAttack)); } } }
C 解法, 执行用时: 2ms, 内存消耗: 372KB, 提交时间: 2020-09-09
#include <stdio.h> int main() { int HP,normalAttack,buffedAttack,num; scanf("%d",&HP); scanf("%d",&normalAttack); scanf("%d",&buffedAttack); if(normalAttack*2>buffedAttack) { num=HP/normalAttack; if(HP%normalAttack!=0) { num++; } } else { num=HP/buffedAttack * 2; if(HP%buffedAttack!=0) { if(HP%buffedAttack>normalAttack) { num+=2; } else { num++; } } } printf("%d\n",num); return 0; } /*#include <stdio.h> int main() { int HP,buff,norm; int i=0,j=0,k=0,p=0; scanf("%d",&HP); scanf("%d",&norm); scanf("%d",&buff); double n1=HP,n2=HP,n3=HP,n4=HP; while(n1>0) { n1=n1-norm; i++; } while(n2>0) { n2=n2-buff; j+=2;; } while(n3>0) { n3=n3-buff; k+=2;; n3=n3-norm; k++; } while(n4>0) { n4=n4-norm; p++; n4=n4-buff; p+=2;; } int a[4]={i,j,k,p}; for(int w=0;w<3;w++) { for(int e=0;e<4-1-w;e++) { if(a[e+1]<a[e]) { int temp=a[e+1]; a[e+1]=a[e]; a[e]=temp; } } } printf("%d\n",a[0]); return 0; }*/
C++14 解法, 执行用时: 2ms, 内存消耗: 372KB, 提交时间: 2020-08-03
#include <cstdio> #include <cmath> int main(){ long long s, b, n; scanf("%lld%lld%lld", &s, &n, &b); if (2*n < b){ int t = s / b; int r = s % b; if (!r) printf("%lld\n", 2*t); else { if (r <= n) printf("%lld\n", 2*t + 1); else printf("%lld\n", 2*t + 2); } } else{ printf("%lld\n", (long long)(ceil(s*1.0/n))); } return 0; }
C 解法, 执行用时: 2ms, 内存消耗: 372KB, 提交时间: 2020-05-01
#include<stdio.h> main() { int hp; while(scanf("%d",&hp)!=EOF) { int normal,buff,min,k,remain; scanf("%d\n%d",&normal,&buff); if (buff<=2*normal) { min=hp/normal; remain=hp-min*normal; if(remain==0) min=min; else min=min+1; } else { k=hp/buff; min=k*2; remain=hp-k*buff; if (remain==0) min=min; else if(remain<=normal) min=min+1; else min=min+2; } printf("%d",min); } }