runtime-error - 提交时它给出 runtime_error
问题描述
t=int(input())
while t>0 :
c=0
n,h,y1,y2,e = list(map(int, input().split()))
for i in range(n):
x0,x1 = list(map(int, input().split()))
if x0==1 :
if x1 < h-y1:
e -= 1
else :
if y2 < x1 :
e -= 1
if e>0 :
c+=1
else :
break
print(c)
t-=1
它正在通过示例测试用例,但在提交时,它显示出现运行时错误(NZEC)。
解决方案
问题是您正在读取输入并同时处理它们。因此,在某些测试用例中可能会出现这样的情况,e<=0
但您仍然需要x0 x1
阅读一些内容(即i<n-1
)。在这种情况下,您将break
进入循环,因为e<=0
在循环的下一次迭代中while
,您将尝试读取 5 个值n,h,y1,y2,e = list(map(int, input().split()))
,但您只会收到 2 个值x0 x1
,因此它会抛出 a ValueError: not enough values to unpack (expected 5, got 2)
,因此它不会通过所有测试案例。
要解决此问题,只需先获取所有输入,然后根据您当前的逻辑处理它们。
t=int(input())
while t>0 :
c=0
n,h,y1,y2,e = list(map(int, input().split()))
inputs = []
for i in range(n):
inputs.append(list(map(int, input().split())))
for inp in inputs:
x0,x1 = inp
if x0==1 :
if x1 < h-y1:
e -= 1
else :
if y2 < x1 :
e -= 1
if e>0 :
c+=1
else :
break
print(c)
t -= 1
推荐阅读
- dataframe - PySpark 如何使用不匹配的键有效地连接 2 个 DataFrame
- reactjs - 使用 fetch 功能对我的反应应用程序接收到 CORS 错误
- java - 从 Java 运行 exec 命令是否需要“bash”?
- python - 无法理解的结果
- google-bigquery - 为什么在我引入子查询时 BigQuery 会抱怨左连接错误?
- r - 在数据框中选择观察并颠倒它们的顺序
- sql - Bigquery 日期间隔语法
- r - 在函数中将字符串作为参数传递时如何保留列名
- asp.net-mvc - .Net Core MVC RedirectToRoutePermanent 不会重定向到匹配的操作
- c - 有人可以解释以下代码的函数pop(更具体地说是变量retval)吗?