楼主: newkid

[每日一题] puzzleup 2018

[复制链接]
论坛徽章:
548
生肖徽章2007版:猴
日期:2008-05-16 11:28:59生肖徽章2007版:马
日期:2008-10-08 17:01:01SQL大赛参与纪念
日期:2011-04-13 12:08:17授权会员
日期:2011-06-17 16:14:53ITPUB元老
日期:2011-06-21 11:47:01ITPUB官方微博粉丝徽章
日期:2011-07-01 09:45:27ITPUB十周年纪念徽章
日期:2011-09-27 16:30:472012新春纪念徽章
日期:2012-01-04 11:51:222012新春纪念徽章
日期:2020-11-30 22:13:24海蓝宝石
日期:2012-02-20 19:24:27
361#
发表于 2018-12-13 09:38 | 只看该作者
lugionline 发表于 2018-12-13 08:42
在MMA的强大攻势下,完全不堪一击

In[2]:= 6!*(1/1! + 1/2! + 1/3!)

牛B啊,公式都被你整出来了!

使用道具 举报

回复
论坛徽章:
548
生肖徽章2007版:猴
日期:2008-05-16 11:28:59生肖徽章2007版:马
日期:2008-10-08 17:01:01SQL大赛参与纪念
日期:2011-04-13 12:08:17授权会员
日期:2011-06-17 16:14:53ITPUB元老
日期:2011-06-21 11:47:01ITPUB官方微博粉丝徽章
日期:2011-07-01 09:45:27ITPUB十周年纪念徽章
日期:2011-09-27 16:30:472012新春纪念徽章
日期:2012-01-04 11:51:222012新春纪念徽章
日期:2020-11-30 22:13:24海蓝宝石
日期:2012-02-20 19:24:27
362#
发表于 2018-12-13 09:54 | 只看该作者
solomon_007 发表于 2018-12-13 09:37
的确,2指数应该按0算起,这样就是 2^n-1 算总和;
另外,sets.last_code

借鉴一下:

SQL> with t as (select chr(64+level) c,power(2,level-1) b from dual connect by level <= 6),
  2       code(lvl,str,bsum) as (select 1,c,b from t
  3                               union all
  4                              select lvl + 1,
  5                                     str||t.c,
  6                                     bsum + t.b
  7                                from code,t
  8                               where bitand(bsum,t.b) = 0),
  9  set_code(lvl,set_str,set_sum,last_str) as (select 1,'('||str,bsum,str
10                                               from code
11                                              where lvl>1
12                                              union all
13                                             select set_code.lvl + 1,
14                                                    set_str||','||code.str,
15                                                    set_sum + bsum,
16                                                    code.str
17                                               from set_code,code
18                                              where bitand(set_sum,bsum) = 0
19                                                and code.lvl > 1
20                                                and set_code.last_str < code.str
21                                                and set_sum < power(2,6)-1)
22  select count(set_str||')')
23    from set_code
24   where lvl > 1
25     and set_sum = power(2,6)-1
26  /
COUNT(SET_STR||')')
-------------------
               1200

使用道具 举报

回复
论坛徽章:
407
紫蛋头
日期:2012-05-21 10:19:41迷宫蛋
日期:2012-06-06 16:02:49奥运会纪念徽章:足球
日期:2012-06-29 15:30:06奥运会纪念徽章:排球
日期:2012-07-10 21:24:24鲜花蛋
日期:2012-07-16 15:24:59奥运会纪念徽章:拳击
日期:2012-08-07 10:54:50奥运会纪念徽章:羽毛球
日期:2012-08-21 15:55:33奥运会纪念徽章:蹦床
日期:2012-08-21 21:09:51奥运会纪念徽章:篮球
日期:2012-08-24 10:29:11奥运会纪念徽章:体操
日期:2012-09-07 16:40:00
363#
发表于 2025-2-19 20:16 | 只看该作者
第一题:deekseek前面给的程序又慢,结果也不对,提示它思路后,给出了正确的程序

  1. import itertools
  2. import math

  3. def is_triangle(a, b, c):
  4.     # 检查是否满足三角形不等式
  5.     return a + b > c and a + c > b and b + c > a

  6. def triangle_area(a, b, c):
  7.     # 计算三角形面积(海伦公式)
  8.     s = (a + b + c) / 2
  9.     return math.sqrt(s * (s - a) * (s - b) * (s - c))

  10. def max_area_optimized():
  11.     # 总长度为 100
  12.     total_length = 100
  13.     # 最大面积
  14.     max_total_area = 0
  15.     # 最大面积时的矩形面积
  16.     max_rectangle_area = 0
  17.     # 最大面积时的分配方式
  18.     best_allocation = None

  19.     # 遍历正方形边长 d
  20.     for d in range(23, 0, -1):
  21.         # 正方形需要 4 段,每段长度为 d
  22.         square_length = 4 * d
  23.         remaining_length = total_length - square_length

  24.         # 剩余长度需要分配给矩形和三角形
  25.         # 矩形需要 4 段,其中两段为 e,两段为 f
  26.         # 三角形需要 3 段,分别为 a, b, c
  27.         # 剩余长度必须满足:2e + 2f + a + b + c = remaining_length

  28.         # 遍历矩形边长 e 和 f
  29.         for e in range(1, remaining_length // 2 + 1):
  30.             for f in range(1, remaining_length // 2 + 1):
  31.                 if e == f:
  32.                     continue  # 矩形不能是正方形
  33.                 # 矩形需要 2e + 2f
  34.                 rectangle_length = 2 * e + 2 * f
  35.                 if rectangle_length > remaining_length:
  36.                     continue  # 矩形周长超过剩余长度

  37.                 # 剩余长度分配给三角形
  38.                 triangle_length = remaining_length - rectangle_length
  39.                 # 三角形需要 3 段,分别为 a, b, c
  40.                 # 遍历三角形的边长
  41.                 for a in range(1, triangle_length // 3 + 1):
  42.                     for b in range(a, (triangle_length - a) // 2 + 1):
  43.                         c = triangle_length - a - b
  44.                         if is_triangle(a, b, c):
  45.                             # 计算面积
  46.                             square_area = d ** 2
  47.                             rectangle_area = e * f
  48.                             triangle_area_val = triangle_area(a, b, c)
  49.                             total_area = square_area + rectangle_area + triangle_area_val
  50.                             # 更新最大面积
  51.                             if total_area > max_total_area:
  52.                                 max_total_area = total_area
  53.                                 max_rectangle_area = rectangle_area
  54.                                 best_allocation = {
  55.                                     "square": [d, d, d, d],
  56.                                     "rectangle": [e, e, f, f],
  57.                                     "triangle": [a, b, c],
  58.                                     "total_area": total_area
  59.                                 }

  60.     return max_rectangle_area, best_allocation

  61. # 计算最大矩形面积
  62. result, allocation = max_area_optimized()
  63. print(f"最大总面积时,矩形的面积是:{result}")
  64. print(f"**分配方式:{allocation}")
复制代码

使用道具 举报

回复
论坛徽章:
407
紫蛋头
日期:2012-05-21 10:19:41迷宫蛋
日期:2012-06-06 16:02:49奥运会纪念徽章:足球
日期:2012-06-29 15:30:06奥运会纪念徽章:排球
日期:2012-07-10 21:24:24鲜花蛋
日期:2012-07-16 15:24:59奥运会纪念徽章:拳击
日期:2012-08-07 10:54:50奥运会纪念徽章:羽毛球
日期:2012-08-21 15:55:33奥运会纪念徽章:蹦床
日期:2012-08-21 21:09:51奥运会纪念徽章:篮球
日期:2012-08-24 10:29:11奥运会纪念徽章:体操
日期:2012-09-07 16:40:00
364#
发表于 2025-2-19 20:47 | 只看该作者
63楼的题deepseek直接做对了

  1. from collections import deque

  2. def water_bucket_bfs():
  3.     # 定义水桶容量
  4.     capacities = (43, 59, 100)
  5.     # 初始状态
  6.     initial_state = (0, 0, 100)
  7.     # 目标状态
  8.     target_state = (0, 50, 50)

  9.     # 使用 BFS 搜索
  10.     queue = deque()  # 存储待探索的状态
  11.     queue.append((initial_state, []))  # (当前状态, 路径)
  12.     visited = set()  # 存储已访问的状态

  13.     while queue:
  14.         current_state, path = queue.popleft()
  15.         if current_state == target_state:
  16.             # 找到目标状态,输出路径
  17.             return path + [current_state]

  18.         if current_state in visited:
  19.             continue
  20.         visited.add(current_state)

  21.         # 生成所有可能的下一步状态
  22.         a, b, c = current_state
  23.         # 从 3 升桶倒水
  24.         if a > 0:
  25.             # 3 升桶倒入 5 升桶
  26.             pour_amount = min(a, capacities[1] - b)
  27.             new_state = (a - pour_amount, b + pour_amount, c)
  28.             queue.append((new_state, path + [current_state]))
  29.             # 3 升桶倒入 8 升桶
  30.             pour_amount = min(a, capacities[2] - c)
  31.             new_state = (a - pour_amount, b, c + pour_amount)
  32.             queue.append((new_state, path + [current_state]))
  33.         # 从 5 升桶倒水
  34.         if b > 0:
  35.             # 5 升桶倒入 3 升桶
  36.             pour_amount = min(b, capacities[0] - a)
  37.             new_state = (a + pour_amount, b - pour_amount, c)
  38.             queue.append((new_state, path + [current_state]))
  39.             # 5 升桶倒入 8 升桶
  40.             pour_amount = min(b, capacities[2] - c)
  41.             new_state = (a, b - pour_amount, c + pour_amount)
  42.             queue.append((new_state, path + [current_state]))
  43.         # 从 8 升桶倒水
  44.         if c > 0:
  45.             # 8 升桶倒入 3 升桶
  46.             pour_amount = min(c, capacities[0] - a)
  47.             new_state = (a + pour_amount, b, c - pour_amount)
  48.             queue.append((new_state, path + [current_state]))
  49.             # 8 升桶倒入 5 升桶
  50.             pour_amount = min(c, capacities[1] - b)
  51.             new_state = (a, b + pour_amount, c - pour_amount)
  52.             queue.append((new_state, path + [current_state]))

  53.     return None  # 如果没有找到解

  54. # 运行 BFS 搜索
  55. path = water_bucket_bfs()
  56. if path:
  57.     print("变化路径:")
  58.     for state in path:
  59.         print(state)
  60. else:
  61.     print("未找到解。")
复制代码

使用道具 举报

回复
论坛徽章:
407
紫蛋头
日期:2012-05-21 10:19:41迷宫蛋
日期:2012-06-06 16:02:49奥运会纪念徽章:足球
日期:2012-06-29 15:30:06奥运会纪念徽章:排球
日期:2012-07-10 21:24:24鲜花蛋
日期:2012-07-16 15:24:59奥运会纪念徽章:拳击
日期:2012-08-07 10:54:50奥运会纪念徽章:羽毛球
日期:2012-08-21 15:55:33奥运会纪念徽章:蹦床
日期:2012-08-21 21:09:51奥运会纪念徽章:篮球
日期:2012-08-24 10:29:11奥运会纪念徽章:体操
日期:2012-09-07 16:40:00
365#
发表于 2025-2-19 21:35 | 只看该作者
18题,腾讯元宝用它自己T1模型啰嗦半天不出结果,用它带的deepseek啰嗦了6分钟,出结果了,一次算对

  1. import math
  2. from collections import deque

  3. def is_prime(n):
  4.     if n <= 1:
  5.         return False
  6.     if n == 2:
  7.         return True
  8.     if n % 2 == 0:
  9.         return False
  10.     for i in range(3, int(math.sqrt(n)) + 1, 2):
  11.         if n % i == 0:
  12.             return False
  13.     return True

  14. def find_largest_right_truncatable_prime():
  15.     queue = deque([2, 3, 5, 7])
  16.     max_prime = 0
  17.     while queue:
  18.         current = queue.popleft()
  19.         if current > max_prime:
  20.             max_prime = current
  21.         for digit in [1, 3, 7, 9]:
  22.             new_num = current * 10 + digit
  23.             if is_prime(new_num):
  24.                 queue.append(new_num)
  25.     return max_prime

  26. print(find_largest_right_truncatable_prime())
复制代码

使用道具 举报

回复
论坛徽章:
520
奥运会纪念徽章:垒球
日期:2008-09-15 01:28:12生肖徽章2007版:鸡
日期:2008-11-17 23:40:58生肖徽章2007版:马
日期:2008-11-18 05:09:48数据库板块每日发贴之星
日期:2008-11-29 01:01:02数据库板块每日发贴之星
日期:2008-12-05 01:01:03生肖徽章2007版:虎
日期:2008-12-10 07:47:462009新春纪念徽章
日期:2009-01-04 14:52:28数据库板块每日发贴之星
日期:2009-02-08 01:01:03生肖徽章2007版:蛇
日期:2009-03-09 22:18:532009日食纪念
日期:2009-07-22 09:30:00
366#
 楼主| 发表于 2025-2-19 22:38 | 只看该作者
请提示用SQL完成解题。

使用道具 举报

回复

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

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表