python - 代码厨师 | 卧推问题 - 我用示例测试用例解决了这个问题并部分解决了它。你能指出我错过了什么吗
问题描述
Python3 代码:
testCases = int(input())
for i in range(testCases):
line1 = [int(x) for x in input().split()]
weights = [int(y) for y in input().split()]
numberOfWeights,requiredWeight,rodWeight = line1[0],line1[1],line1[2]
if (requiredWeight <= rodWeight):
print("YES")
continue
lookupWeights = list()
for j in range(numberOfWeights):
if (requiredWeight <= rodWeight):
break
if(weights[j] in lookupWeights):
rodWeight += (2*weights[j])
lookupWeights.remove(weights[j])
else:
lookupWeights.append(weights[j])
if (requiredWeight <= rodWeight):
print("YES")
else:
print("NO")
我已经尝试了很多测试用例,它似乎仍然可以正常工作,但没有被接受提交。现在我知道代码效率不高。我所需要的只是一个示例测试用例来破坏此代码/逻辑。
示例测试用例 1:
3
2 5 10
2 2
7 100 50
100 10 10 10 10 10 90
6 100 40
10 10 10 10 10 10
Output:
YES
NO
YES
TEST CASE 2:
1
8 100 40
10 20 10 25 30 40 30 50
Output:
YES
解决方案
推荐阅读
- python - 使用 Google Apps 脚本的考勤系统
- ruby - 带有Ruby的Windows上的Git Bash:在打印提示之前等待gets()输入?
- json - Xamarin Forms - 从 RestAPI 加载 JSON 的最佳实践
- javascript - 我希望 angular5 PDF 查看器插件在 ionic3 应用程序和 Web 应用程序中使用
- docker - 如何为 HyperLedger Playground 安装运行 docker?
- sql - 如何在 CTE 中使用存储过程
- reactjs - 在 redux 存储中的状态更改和相应的反应状态更改之间进行交互的正确方法
- python - Python Selenium send_keys 函数发送部分文本
- javascript - 如何在 WP 自定义页面中包含自定义 JS 文件
- vue.js - VueDraggable : 只允许克隆