OJ 比赛列表有蓝桥杯、CCF-CSP、天梯赛官方练习系统 / 题目集入口,有需要测试比赛评测环境的可以前往。

python是yyds

softman 发表于 1个月前 · 关联问题 一鸣师姐与阿枯城

import math #需要用一个math里面的ceil函数 def fastsort(lister): lengh = len(lister) for i in range(1, lengh): pre = lister[i - 1][2] while i >= 1 and lister[i][2] < pre: lister[i - 1][2] = lister[i][2] lister[i][2] = pre i -= 1 pre = lister[i - 1][2] return lister #简单的排序算法 def timecount(ming,demon): hp = ming[0] ark = ming[1] hp_demon = demon[0] ark_demon = demon[1] count_ming = math.ceil(hp_demon / ark) count_demon = math.ceil(hp / ark_demon) if count_ming < count_demon: k = 1 else: k = 0 hp -= count_ming * ark_demon return [k, count_ming, hp] # k 是帮助判断的值,k = 0 说明一鸣师姐打不过怪物,hp则是返回战斗后剩余hp,count———ming是一个帮助下一步判断的变量,它是一鸣师姐击败怪物需要的时间 ming = [int(i)for i in str(input()).split()] n = int(input()) lister = [] resumetime = ming[2] hp = ming[0] origion_hp = ming[0] ark = ming[1] judge = 1 #judge 也是一个帮助判断的变量 for i in range(n): demon = [int(i)for i in str(input()).split()] lister.append(demon) #处理一下数据,按照时间排序一下 lister = fastsort(lister) alter = 0 for i in lister: alter += 1 data_return = timecount(ming, i) k = data_return[0] sumtime = data_return[1] ming[0] = data_return[2] time = i[2] if alter <= len(lister) - 1: curtime = lister[alter - 1][2] + sumtime nexttime = lister[alter][2] else: curtime = lister[alter - 1][2] + sumtime nexttime = curtime if k == 0: print('My Milk!') judge = 0 break elif curtime > nexttime: print('My Milk!') judge = 0 break elif nexttime - curtime >= resumetime: hp = ming[0] hp += ming[3] ming[0] = min(hp, origion_hp) # 一鸣失败有两种情况,一是打不过怪物成眠了,函数返回k是0,另外一种就是同时多个怪物,就是利用了curtime和nexttime两个变量判断,前者是打败这只怪物的时候,后者是下一个怪物出现的时候,如果curtime 》 nexttime说明会同时出现多个怪物 if judge == 1: print('Mission Complete.')