拼夕夕-笔试-算法
1. 输入三个数,怪物HP,普通攻击normal_attack,蓄力攻击buffer_attack(蓄力一回合,下回合蓄力攻击),求杀死怪物最小回合
``` def cal(hp, na, ba): round = 0 if hp <= na or na * 2<ba if hp/na == 0: return int(hp/na) return int(hp/na) + 1 while hp > na: round += 2 hp -= ba if hp > 0: return round + 1 return round ```
3.输入两个数a,b,输出a / b 商的循环小数前一个位置 和 循环长度(不循环为0)
1 3 out : 0 1
5 4 out : 2 0
def cal(a, b): yushu = a % b pos, length = 0, 0 yushu_list = [] while yushu != 0: yushu = yushu * 10 % b for i, ys in enumerate(yushu_list): if ys == yushu: length = len(yushu_list) - i return pos-1, length yushu_list.append(yushu) pos += 1 return pos, length
```
#拼多多##题解##笔试题目#