今天做一个oj题目Biorhythms,按给定的示例可以通过,但是提交总是wa(Wrong Answer),但是又看不到错误信息,于是找到了一个工具网站https://loj.ac/problem/10217练习,这个工具最大的好处可以看到输出是否错误,于是乎就按着这个工具的数据进行修改,发现自己的代码缺少了一些判断条件,于是根据对应的数据和输出修改最终通过,但是不知道这算不算作弊😱。
下面是我修改后的代码,虽然最后通过了,但是耗时比较长,仍有很大进步空间,有时间再改改。
# -*- coding: UTF-8 -*- # 最小值的索引 def min_index(tmp): i = 0; if tmp[1] < tmp[0]: i = 1; if tmp[2] < tmp[1]: i = 2; return i; # 重复值 def repeat_value(temp_list): res = -1; # 周期 cycle_list = [23, 28, 33]; while True: # 如果三个值相等表示达到三重峰值,且需要此日期大于给定日期 if temp_list[0] == temp_list[1] and temp_list[1] == temp_list[2] and temp_list[0] > temp_list[3]: # 计算相差天数 res = temp_list[0] - temp_list[3]; break; # 最小值的索引 min_i = min_index(temp_list); # 最小值加上其对应的周期天数 temp_list[min_i] += cycle_list[min_i]; # 最小值大于等于给定日期数则认为是最大的周期值 if temp_list[min_i] >= temp_list[3] + 21252: res = 21252; break; return res; # 序号 index = 0; # 周期 cycle_list = [23, 28, 33]; # 循环破解,直至三值相等 while True: # 去除首尾的空格并按空格切分字符 temp = list(input().strip().split(" ")); # 结束符 if temp[0] == "-1" and temp[1] == "-1" and temp[2] == "-1" and temp[3] == "-1": break; # 存放数字的list temp_list = list(); # 结果值 res = 0; # 序号 index += 1; ii = 0; # 最小峰值日期 min_temp_list = list(); for i in temp: # 转为int num = int(i); if ii < 3 and num >= 365: num = 365; if num <= 0: num = 0; temp_list.append(num); if ii < 3: num = num % cycle_list[ii]; min_temp_list.append(num); ii += 1; res = repeat_value(min_temp_list); print("Case " + str(index) + ": the next triple peak occurs in " + str(res) + " days.");