手机安装python jam有什么影响_对于codejam练习,我的解决方案或输出方法有什么不正确的地方?...

我参加了谷歌代码堵塞大赛的kickstart,结果被称为Gbus计数的问题1A困住了

我的代码正在通过问题中提供的示例测试用例,但是当我通过将其输出到一个文件来提交小输入时,它会给我一个错误的、错误的响应。在t=int(input()) #no. of test cases

for test in range(t):

if test==0:

n=int(input())

else:

input() #to cover up the blank line after each test case

n=int(input())

l=list(map(int,input().split()))

buses={} # the route of each bus will be stored in this dictionary

i=1

for d in l: # this loop is used to store the route of each bus in the buses dictionary

if i not in buses:

buses[i]=[d]

elif len(buses[i])<2:

buses[i].append(d)

else:

i=i+1

buses[i]=[d]

p=int(input())

cities={}

#this dictionary will contain the cities which need to be monitored

for _ in range(p): #first each city is initialized to zero

cities[int(input())]=0

for city in cities: #Monitor all buses in each city if it falls in the route range than increment the city

for bus in buses:

if buses[bus][0]<=city<=buses[bus][1]:

cities[city]+=1

result=[]

for city in cities: #store all the cities in a list

result.append(cities[city])

print("Case #{}: {}".format(test+1, ' '.join(map(str,result))))

我的逻辑:

首先,我把所有的测试用例放在一个变量t中,对于每个测试用例,我在一个列表l中输入总线的数量和所有总线的输入路径。然后我创建了一个名为bus的字典,并将列表分成n个列表,每个列表在字典中从1到n表示每个bus nume=beres。在

然后我在另一个名为cities的字典中输入所有要监视的城市,并将每个要监视的城市的值初始化为0。在

最后,我通过检查每个城市是否在每辆公共汽车的路线范围内计算出经过每个城市的公共汽车数量,如果是,我将相应城市的值增加1,然后将字典的所有值存储在一个列表中,并为每个测试用例输出它。在

输出方法:

我用这行代码在我的工作目录中使用cmd来执行代码

^{pr2}$

我的代码对于所提供的示例测试用例运行良好,因此我的逻辑中可能没有缺陷。我认为我的输出方法可能有错误。在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值