洛谷_P1014 [NOIP1999 普及组] Cantor 表_python写法

这道题其实没什么特别的,最重要就是仔细分析找到其中的数学规律。

以斜着为行,每一行的数值就是与第几行有关。

那对于Z字形而言就是行数的奇偶判断。

python 复制代码
n = int(input())
ans = 0
flag = 0
l = ['0']
while ans < n:
    flag += 1
    ans += flag
ans -= flag
n -= ans
j = flag
if flag%2 == 0:
    for i in range(1,flag+1):
        s = str(i) + '/' + str(j)
        j -= 1
        l.append(s)
else:
    for i in range(1,flag+1):
        s = str(j) + '/' + str(i)
        j -= 1
        l.append(s)
print(l[n])
相关推荐
花酒锄作田1 小时前
[python]argparse 包在聊天机器人中的应用
python
NiceCloud喜云3 小时前
Opus 4.8 的 Effort Control 怎么选:Low 到 Max 五档策略
android·java·大数据·前端·c++·python·spring
wordbaby4 小时前
React Native + RNOH:跨页面数据回传的最佳实践与避坑指南
前端·react native
丷丩4 小时前
MapLibre GL JS第22课:查看本地GeoJSON
前端·javascript·map·mapbox·maplibre gl js
AI玫瑰助手4 小时前
Python函数:默认参数的定义与注意事项
开发语言·python·信息可视化
weixin_468466854 小时前
全局与局部注意力机制新手实战指南
人工智能·python·深度学习·算法·自然语言处理·transformer·注意力机制
油炸自行车4 小时前
Claude Code 错误:API Error: 400 Failed to deserialize the JSON body into the
开发语言·javascript·json·trae·claude code·api error 400
肩上风骋4 小时前
C++14特性
开发语言·c++·c++14特性
小糖学代码4 小时前
LLM系列:环境搭建:5.Python-dotenv 环境变量管理
人工智能·python·深度学习·神经网络
智慧物业老杨5 小时前
智慧物业合同周期管理系统:从风险预警到智能交接的全流程数智化落地方案
java·人工智能·python