鱼C论坛

 找回密码
 立即注册
12
返回列表 发新帖
楼主: zltzlt

[已解决]Python:每日一题 377

[复制链接]
 楼主| 发表于 2020-4-16 20:48:13 | 显示全部楼层
March2615 发表于 2020-4-16 12:57
不知不觉一下午过去了

17 ms
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2020-4-16 20:49:10 | 显示全部楼层
TJBEST 发表于 2020-4-16 14:58
来看看我的史诗巨作,历时1个小时20分钟

输入以下数据超时:

testcase.zip (3.73 KB, 下载次数: 1)
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2020-4-16 20:50:10 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2020-4-16 20:51:25 | 显示全部楼层
whosyourdaddy 发表于 2020-4-16 20:11
def func377(arr):
    def distance( p,  q):
        return (p[0]-q[0]) * (p[0]-q[0]) + (p[1]-q[1]) ...

解答错误

输入:
  1. [[3, 7], [6, 8], [7, 8], [11, 10], [4, 3], [8, 5], [7, 13], [4, 13]]
复制代码

输出:
  1. [[3, 7], [6, 8], [11, 10], [4, 3], [8, 5], [4, 13]]
复制代码

预期结果:
  1. [[3, 7], [7, 13], [11, 10], [8, 5], [4, 13], [4, 3]]
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-4-16 21:35:12 | 显示全部楼层
  1. import math
  2. def f377(points):
  3.     n = len(points)
  4.     if n == 0:
  5.         return 0
  6.     if n <= 3:
  7.         return points
  8.    
  9.     def get_bottom_point(points):
  10.         min_index = 0
  11.         n = len(points)
  12.         for i in range(0, n):
  13.             if points[i][1] < points[min_index][1] or (points[i][1] == points[min_index][1] and points[i][0] < points[min_index][0]):
  14.                 min_index = i
  15.         return min_index

  16.     def f2(points, center_point):
  17.         n = len(points)
  18.         cos_value = []
  19.         rank = []
  20.         norm_list = []
  21.         for i in range(0, n):
  22.             point_ = points[i]
  23.             point = [point_[0]-center_point[0], point_[1]-center_point[1]]
  24.             rank.append(i)
  25.             norm_value = math.sqrt(point[0]*point[0] + point[1]*point[1])
  26.             norm_list.append(norm_value)
  27.             if norm_value == 0:
  28.                 cos_value.append(1)
  29.             else:
  30.                 cos_value.append(point[0] / norm_value)
  31.         for i in range(0, n-1):
  32.             index = i + 1
  33.             while index > 0:
  34.                 if cos_value[index] > cos_value[index-1] or (cos_value[index] == cos_value[index-1] and norm_list[index] > norm_list[index-1]):
  35.                     temp = cos_value[index]
  36.                     temp_rank = rank[index]
  37.                     temp_norm = norm_list[index]
  38.                     cos_value[index] = cos_value[index-1]
  39.                     rank[index] = rank[index-1]
  40.                     norm_list[index] = norm_list[index-1]
  41.                     cos_value[index-1] = temp
  42.                     rank[index-1] = temp_rank
  43.                     norm_list[index-1] = temp_norm
  44.                     index = index-1
  45.                 else:
  46.                     break
  47.         sorted_points = []
  48.         for i in rank:
  49.             sorted_points.append(points[i])
  50.      
  51.         return sorted_points
  52.    
  53.     def vector_angle(vector):
  54.         norm_ = math.sqrt(vector[0]*vector[0] + vector[1]*vector[1])
  55.         if norm_ == 0:
  56.             return 0
  57.      
  58.         angle = math.acos(vector[0]/norm_)
  59.         if vector[1] >= 0:
  60.             return angle
  61.         else:
  62.             return 2*math.pi - angle
  63.      
  64.     def coss_multi(v1, v2):
  65.         return v1[0]*v2[1] - v1[1]*v2[0]

  66.     bottom_index = get_bottom_point(points)
  67.     bottom_point = points.pop(bottom_index)
  68.     sorted_points = f2(points, bottom_point)
  69.     m = len(sorted_points)
  70.     if m <2 :
  71.         return points
  72.     stack = []
  73.     stack.append(bottom_point)
  74.     stack.append(sorted_points[0])
  75.     stack.append(sorted_points[1])
  76.     for i in range(2, m):
  77.         length = len(stack)
  78.         top = stack[length-1]
  79.         next_top = stack[length-2]
  80.         v1 = [sorted_points[i][0]-next_top[0], sorted_points[i][1]-next_top[1]]
  81.         v2 = [top[0]-next_top[0], top[1]-next_top[1]]
  82.         while coss_multi(v1, v2) > 0:
  83.             stack.pop()
  84.             length = len(stack)
  85.             top = stack[length-1]
  86.             next_top = stack[length-2]
  87.             v1 = [sorted_points[i][0] - next_top[0], sorted_points[i][1] - next_top[1]]
  88.             v2 = [top[0] - next_top[0], top[1] - next_top[1]]

  89.         stack.append(sorted_points[i])
  90.     return stack

  91. print(f377([[1, 2], [2, 2], [4, 2]]))
  92. print(f377([[1, 1], [2, 2], [2, 0], [2, 4], [3, 3], [4, 2]]))
复制代码

评分

参与人数 1荣誉 +3 鱼币 +3 收起 理由
zltzlt + 3 + 3

查看全部评分

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2020-4-16 22:43:22 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-4-17 11:09:10 | 显示全部楼层
数学不好的人飘过...高等数学没有学过...怎么办
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-4-17 11:16:20 | 显示全部楼层
本帖最后由 TJBEST 于 2020-4-17 17:18 编辑

楼主帮忙测测吧 @zltzlt
  1. def fun377(points):
  2.     if len(points) < 4:
  3.         return points
  4.     dealWith = sorted(points)
  5.     Left = dealWith[0]
  6.     Right = dealWith[-1]
  7.     del dealWith[0]
  8.     result = [Left]
  9.    
  10.     previous = Left
  11.     while True:
  12.         if previous[0] == Left[0]:
  13.             comList = [i for i in dealWith if (i[0]> previous[0]) or (i[1] > previous[1])]
  14.         elif previous[0] == Right[0]:
  15.             comList = [i for i in dealWith if (i[0]== previous[0]) and (i[1] < previous[1])]
  16.         else:
  17.             comList = [i for i in dealWith if i[0]> previous[0]]
  18.         comList.sort()
  19.         if comList[0][0] == Left[0]:
  20.             previous = comList[0]
  21.             result.append(previous)
  22.             dealWith.remove(previous)
  23.         elif previous[0] == Right[0]:
  24.             previous = comList[-1]
  25.             result.append(previous)
  26.             dealWith.remove(previous)
  27.         else:
  28.             comList.sort(key = lambda ex:(((ex[1]-previous[1])/(ex[0]-previous[0])),-ex[0]))
  29.             previous = comList.pop()
  30.             result.append(previous)
  31.             dealWith.remove(previous)
  32.         if previous == Right:
  33.             break
  34.     dealWith.append(Left)
  35.     while True:
  36.         if previous[0] == Left[0]:
  37.             comList = [i for i in dealWith if (i[0]==previous[0]) and (i[1] > previous[1])]
  38.         elif previous[0] == Right[0]:
  39.             comList = [i for i in dealWith if (i[0] < previous[0]) or (i[1] < previous[1])]
  40.         else:
  41.             comList = [i for i in dealWith if i[0]< previous[0]]
  42.         comList.sort()
  43.         if comList[-1][0] == Right[0]:
  44.             previous = comList.pop()
  45.             result.append(previous)
  46.             dealWith.remove(previous)
  47.         elif previous[0] == Left[0]:
  48.             previous = comList[0]
  49.             result.append(previous)
  50.             dealWith.remove(previous)
  51.         else:
  52.             comList.sort(key = lambda ex:(((ex[1]-previous[1])/(ex[0]-previous[0])),ex[0]))
  53.             previous = comList.pop()
  54.             result.append(previous)
  55.             dealWith.remove(previous)
  56.         if previous == Left:
  57.             result.remove(Left)
  58.             break
  59.     return result
复制代码

评分

参与人数 1荣誉 +5 鱼币 +5 收起 理由
zltzlt + 5 + 5

查看全部评分

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-4-17 11:33:45 | 显示全部楼层
本帖最后由 kinkon 于 2020-4-17 11:37 编辑

自己想的一个测试用例:[[1, 1], [2, 2], [2, 0], [2, 4], [3, 3], [4, 2], [2, 3], [3, 2],[2, 1]]
输出:[[1, 1], [2, 0], [4, 2], [2, 4], [3, 3]]
IMG_20200417_113432.jpg

评分

参与人数 1荣誉 +2 鱼币 +2 收起 理由
zltzlt + 2 + 2 感谢

查看全部评分

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2020-4-17 13:24:46 | 显示全部楼层

解答错误

输入:
  1. [[3, 0], [4, 0], [5, 0], [6, 1], [7, 2], [7, 3], [7, 4], [6, 5], [5, 5], [4, 5], [3, 5], [2, 5], [1, 4], [1, 3], [1, 2], [2, 1], [4, 2], [0, 3]]
复制代码

输出:
  1. [[3, 0], [5, 0], [6, 1], [7, 2], [7, 3], [7, 4], [6, 5], [5, 5], [4, 5], [3, 5], [2, 5], [1, 4], [1, 3], [1, 2], [2, 1], [0, 3]]
复制代码

预期结果:
  1. [[0, 3], [6, 1], [3, 5], [7, 2], [5, 0], [1, 4], [1, 2], [7, 3], [4, 5], [5, 5], [6, 5], [4, 0], [3, 0], [2, 1], [2, 5], [7, 4]]
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-4-17 17:16:56 | 显示全部楼层
@zltzlt 楼主 新代码见28层
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-4-17 18:13:41 From FishC Mobile | 显示全部楼层
待我上机我来画的试试
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2020-4-17 18:44:32 | 显示全部楼层
TJBEST 发表于 2020-4-17 11:16
楼主帮忙测测吧 @zltzlt

56 ms
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-4-18 01:56:48 | 显示全部楼层
本帖最后由 阴阳神万物主 于 2020-4-18 05:36 编辑

难度评级:普通
要素分析:数论
随机输入生成器送给有需要的人:如果觉得好用,麻烦评个分呗
  1. from random import randint as r
  2. def gent(x=[0,4],y=[0,4],m=8,n=5,f=False):
  3.     '''
  4.     参数说明:
  5.         x:'横轴取值闭区间'默认为[0,4]
  6.         y:'纵轴取值闭区间'默认为[0,4]
  7.         m:'最多允许多少棵树'默认为8
  8.         n:'生成数量'默认生成5个测试数据
  9.         f:'是否固定树的颗数'默认为随机颗树
  10.     '''
  11.     x1,x2 = x
  12.     y1,y2 = y
  13.     size = min((x2-x1+1)*(y2-y1+1),m)
  14.     for i in range(n):
  15.         lst = []
  16.         for j in range(size if f else r(1,size)):
  17.             while 1:
  18.                 pos = [r(x1,x2),r(y1,y2)]
  19.                 if pos not in lst:
  20.                     lst.append(pos)
  21.                     break
  22.         yield lst
复制代码



解题代码1:
  1. def solve(trees:'list og points by list')->list:
  2.     class Func:
  3.         '''
  4.         y = kx + b
  5.         k = (y1-y2)/(x1-x2)
  6.         b = y - kx
  7.         '''
  8.         def __init__(self,p1,p2):
  9.             x1,y1 = p1
  10.             x2,y2 = p2
  11.             self.k = (y1-y2)/(x1-x2) if x1!=x2 else None
  12.             self.b = y1 - self.k*x1 if self.k!=None else x1
  13.         def cmp(self,pos):
  14.             x,y = pos
  15.             if self.k==None:return 0 if x==self.b else 1 if x > self.b else -1
  16.             ny = self.k*x + self.b
  17.             return 0 if y==ny else 1 if y > ny else -1
  18.     res = []
  19.     l = len(trees)
  20.     if l <= 3:return trees
  21.     for a in range(l-1):
  22.         for b in range(a+1,l):
  23.             f =  Func(trees[a],trees[b])
  24.             c = [f.cmp(pos) for pos in trees]
  25.             if not(1 in c and -1 in c):
  26.                 while 0 in c:
  27.                     n = c.index(0)
  28.                     if trees[n] not in res:res.append(trees[n])
  29.                     c[n] += 1
  30.     return res

  31. if __name__ == '__main__':
  32.     print('示例1 输出:',solve([[1, 1], [2, 2], [2, 0], [2, 4], [3, 3], [4, 2]]))
  33.     print('示例2 输出:',solve([[1, 2], [2, 2], [4, 2]]))
复制代码

思路解说:
整体就是一个简单的线性规划问题,所有点两两相连,若所有点都在线的同一侧或者就在线上,那么这条线就是边界。
当然,我上面这个属于是暴力规划,还有更加巧妙的,就是下面那个。

解题代码2:
  1. class Func:
  2.     '''
  3.     y = kx + b
  4.     k = (y1-y2)/(x1-x2)
  5.     b = y - kx
  6.     '''
  7.     def __init__(self,p1,p2):
  8.         x1,y1 = p1
  9.         x2,y2 = p2
  10.         self.k = (y1-y2)/(x1-x2) if x1!=x2 else None
  11.         self.b = y1 - self.k*x1 if self.k!=None else x1
  12.     def cmp(self,pos):
  13.         x,y = pos
  14.         if self.k==None:return 0 if x==self.b else 1 if x > self.b else -1
  15.         ny = round(self.k*x + self.b,1)
  16.         return 0 if y==ny else 1 if y > ny else -1
  17.    
  18. def solve(trees:'list og points by list')->list:
  19.     res = []
  20.     l = len(trees)
  21.     if l <= 3:return trees
  22.     trees.sort()
  23.     a,b = 0,0
  24.     plan = [0]*l#标记非端边界点
  25.     flg = 1
  26.     while flg:
  27.         b = (b+1)%l
  28.         if plan[b]:continue
  29.         if b == a:a = (a+1)%l;b=a
  30.         f =  Func(trees[a],trees[b])#解析直线函数
  31.         c = [f.cmp(pos) for pos in trees]#检查所有点与直线的关系
  32.         if not(1 in c and -1 in c):#所有点均在直线的同一侧,或者在直线上
  33.             online = []
  34.             while 0 in c:
  35.                 n = c.index(0)
  36.                 online.append(trees[n])
  37.                 if trees[n] not in res:res.append(trees[n])#将边界点加入输出列表
  38.                 elif not plan[n]:flg = 0
  39.                 c[n] += 1
  40.                 if n!=a:plan[n] = 1
  41.             online.sort()
  42.             ia = online.index(trees[a])
  43.             ib = online.index(trees[b])
  44.             a = trees.index(online[-1 if ib>ia else 0])
  45.             b = a#从线的一端直接到另一端,跳过中间的已被标记的点
  46.     return res
  47.         
  48. if __name__ == '__main__':
  49.     print('示例1 输出:',solve_1([[1, 1], [2, 2], [2, 0], [2, 4], [3, 3], [4, 2]]))
  50.     print('示例2 输出:',solve_1([[1, 2], [2, 2], [4, 2]]))
  51.    
复制代码

我自己测试的用时是,在51*51的区域内,最多允许60颗树存在,100个随机测试用例
法一平均用时:36.3805ms
法二平均用时:6.2350ms
我自己测试用时的代码:
  1. >>> import time
  2. >>> def pt(b,x=5,y=5):        #在发现输出数据不同时,用平面图的方式呈现出数据,便于肉眼分辨
  3.         plan = [[0]*y for i in range(x)]
  4.         for i,j in b:
  5.                 plan[i][j] = 1
  6.         for line in plan:
  7.                 print(line)

  8. >>> if 1:
  9.         t1,t2 = [],[]
  10.         for each in gent([0,50],[0,50],m=60,n=100):
  11.                 a = time.perf_counter()
  12.                 s1 = solve_1(each)
  13.                 b = time.perf_counter()
  14.                 t1.append((b-a)*1000)
  15.                 a = time.perf_counter()
  16.                 s2 = solve_2(each)
  17.                 b = time.perf_counter()
  18.                 t2.append((b-a)*1000)
  19.                 for each in s1:          #这个二层循环是检查两种方法的结果是否一致的,如不需要,可直接删去
  20.                         if each not in s2:
  21.                                 print('input',len(each))
  22.                                 pt(each,51,51)
  23.                                 print('s1',(s1))
  24.                                 pt(s1,51,51)
  25.                                 print('s2',(s2))
  26.                                 pt(s2,51,51)
  27.                                 break
  28.         print('法一平均用时:%0.4fms\n法二平均用时:%0.4fms\n总共用时%0.4fms'%(sum(t1)/len(t1),sum(t2)/len(t2),sum(t1+t2)))
复制代码


评分

参与人数 1荣誉 +5 鱼币 +5 收起 理由
zltzlt + 5 + 5 给随机输入数据生成器点个赞

查看全部评分

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-4-18 11:45:30 | 显示全部楼层
  1. import math

  2. def fun377(input_list):
  3.     if len (input_list) <4:
  4.         return input_list
  5.     else:
  6.         temp_list = input_list
  7.         
  8.         def test_inner():
  9.             """"
  10.             calc_p 检测点 other_p 其他点的列表
  11.             返回值 : True 是内部点, False 不是内部点
  12.             检测函数 检测点 所有边都不能夹角 找不到大于 pi的
  13.             那么这个点就是内部点,否则就是 位于边界上的点
  14.             """
  15.             vector_list = [(i-calc_p[0], j-calc_p[1]) for i,j in other_p]
  16.             deg_list=[]
  17.             for x,y in vector_list:
  18.                 r = (x**2 +y**2)**0.5
  19.                 deg = math.acos(x/r)
  20.                 if y<0:
  21.                     deg = -deg + math.pi *2
  22.                 deg_list.append(deg)
  23.             deg_list.sort()
  24.             for i in range(len(deg_list)):
  25.                 if i == len(deg_list) -1:
  26.                     if math.pi *2 - deg_list[-1] + deg_list[0]>= math.pi:
  27.                         break
  28.                 elif deg_list[i+1] - deg_list[i] >= math.pi:
  29.                     break
  30.             else:
  31.                 return True
  32.             return False
  33.             
  34.         num = 0 # 从0位置开始 记住上次跳出的 for 循环计数 i 进入下一个for 其实从 i 开始
  35.         while num < len(temp_list):
  36.             for i in range(num, len(temp_list)):   
  37.                 calc_p = temp_list[i]
  38.                 other_p = temp_list[:i] + temp_list[i+1:]
  39.                 if test_inner():
  40.                     temp_list.remove(calc_p)
  41.                     num = i
  42.                     break
  43.             else: # 如果for循环 走完了没有被打断说明 现在for里面的都是外部点
  44.                 return temp_list
  45.         return temp_list
复制代码

评分

参与人数 1荣誉 +4 鱼币 +4 收起 理由
zltzlt + 4 + 4

查看全部评分

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-4-18 16:59:55 | 显示全部楼层
  1. def f(list1):
  2.     def x(list1):
  3.         return list1[0]
  4.     def y(list1):
  5.         return list1[1]
  6.     list2 = []
  7.     list1 = sorted(list1,key=x)
  8.     xmin = list1[0][0]
  9.     xmin_list = []
  10.     xmax = list1[-1][0]
  11.     xmax_list = []
  12.     for each in list1:
  13.         if each[0] == xmin:
  14.             list2.append(each)
  15.             xmin_list.append(each[1])
  16.         elif each[0] == xmax:
  17.             list2.append(each)
  18.             xmax_list.append(each[1])
  19.    
  20.     list1 = sorted(list1,key=y)
  21.     ymin = list1[0][1]
  22.     ymin_list = []
  23.     ymax = list1[-1][1]
  24.     ymax_list = []
  25.     for each in list1:
  26.         if each[1] == ymin:
  27.             list2.append(each)
  28.             ymin_list.append(each[0])
  29.         elif each[1] == ymax:
  30.             list2.append(each)
  31.             ymax_list.append(each[0])

  32.     xmin_list.sort()
  33.     xmax_list.sort()
  34.     ymin_list.sort()
  35.     ymax_list.sort()

  36.     def f1(p1,p2,p3):
  37.         if abs((p2[1]-p1[1])/(p2[0]-p1[0]))<abs((p3[1]-p1[1])/(p3[0]-p1[0])):
  38.             return 2
  39.         elif abs((p2[1]-p1[1])/(p2[0]-p1[0]))==abs((p3[1]-p1[1])/(p3[0]-p1[0])):
  40.             return 1
  41.         else:
  42.             return 0
  43.         
  44.     leftup,leftdown,rightup,rightdown = list1[:],list1[:],list1[:],list1[:]
  45.     p1,p2,p3,p4,p5,p6,p7,p8 = [xmin,xmin_list[-1]],[ymax_list[0],ymax],[ymax_list[-1],ymax],[xmax,xmax_list[-1]],[xmax,xmax_list[0]],[ymin_list[-1],ymin],[ymin_list[0],ymin],[xmin,xmin_list[0]]
  46.     h1,h2,h3,h4 = [],[],[],[]
  47.     while leftup != []:
  48.         for each in leftup.copy():
  49.             if each[0]>=p2[0] or each[1]<=p1[1]:
  50.                 leftup.remove(each)
  51.             else:
  52.                 if f1(p1,p2,each)==2:
  53.                     h1 = []
  54.                     h1.append(each)
  55.                     p2 = each
  56.                 elif f1(p1,p2,each)==1:
  57.                     h1.append(each)
  58.         if h1 != []:
  59.             list2 += h1
  60.             h1 = sorted(h1,key=y)
  61.             p1 = h1[-1]
  62.             p2 = [ymax_list[0],ymax]
  63.             for m in h1:
  64.                 leftup.remove(m)
  65.         else:
  66.             break
  67.     while rightup != []:
  68.         for each in rightup.copy():
  69.             if each[0]<=p3[0] or each[1]<=p4[1]:
  70.                 rightup.remove(each)
  71.             else:
  72.                 if f1(p4,p3,each)==2:
  73.                     h2 = []
  74.                     h2.append(each)
  75.                     p3 = each
  76.                 elif f1(p4,p3,each)==1:
  77.                     h2.append(each)
  78.         if h2 != []:
  79.             list2 += h2
  80.             h2 = sorted(h2,key=y)
  81.             p4 = h2[-1]
  82.             p3 = [ymax_list[-1],ymax]
  83.             for m in h2:
  84.                 rightup.remove(m)
  85.         else:
  86.             break
  87.     while leftdown != []:
  88.         for each in leftdown.copy():
  89.             if each[0]>=p7[0] or each[1]>=p8[1]:
  90.                 leftdown.remove(each)
  91.             else:
  92.                 if f1(p8,p7,each)==2:
  93.                     h4 = []
  94.                     h4.append(each)
  95.                     p7 = each
  96.                 elif f1(p8,p7,each)==1:
  97.                     h4.append(each)
  98.         if h4 != []:
  99.             list2 += h4
  100.             h4 = sorted(h4,key=x)
  101.             p8 = h4[-1]
  102.             p7 = [ymin_list[0],ymin]
  103.             for m in h4:
  104.                 leftdown.remove(m)
  105.         else:
  106.             break
  107.     while rightdown != []:
  108.         for each in rightdown.copy():
  109.             if each[0]<=p6[0] or each[1]>=p5[1]:
  110.                 rightdown.remove(each)
  111.             else:
  112.                 if f1(p5,p6,each)==2:
  113.                     h3 = []
  114.                     h3.append(each)
  115.                     p6 = each
  116.                 elif f1(p5,p6,each)==1:
  117.                     h3.append(each)
  118.         if h3 != []:
  119.             list2 += h3
  120.             h3 = sorted(h3,key=x)
  121.             p5 = h3[0]
  122.             p6 = [ymin_list[-1],ymin]
  123.             for m in h3:
  124.                 rightdown.remove(m)
  125.         else:
  126.             break
  127.     return list2
复制代码

评分

参与人数 1荣誉 +3 鱼币 +3 收起 理由
zltzlt + 3 + 3

查看全部评分

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2020-4-18 17:28:11 | 显示全部楼层
阴阳神万物主 发表于 2020-4-18 01:56
难度评级:普通
要素分析:数论
随机输入生成器,送给有需要的人:如果觉得好用,麻烦评个分呗

两段代码输入以下数据都会超时:

testcase2.zip (3.73 KB, 下载次数: 1)

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2020-4-18 17:30:17 | 显示全部楼层

输入以下数据超时:

testcase2.zip (3.73 KB, 下载次数: 0)
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2020-4-18 17:30:59 | 显示全部楼层

输入 [[1, 2], [2, 2], [4, 2]] 出错
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-19 17:14

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表