我的 Every python 代码在 SPOJ 中提供了 NZEC [英] My Every python code gives NZEC in SPOJ

查看:44
本文介绍了我的 Every python 代码在 SPOJ 中提供了 NZEC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 SPOJ 中使用 Python 完成了一些问题.我猜对了几个.休息一下,我大部分时间都在继续获得 NZEC.我在代码末尾添加了 sys.exit(0) .但它仍然显示相同.

I have done a few questions in SPOJ using Python. I got a few correct. Rest all I keep on getting NZEC most of the time. I added sys.exit(0) at the end of the code. But still it shows the same.

我想知道我的一些写作练习是否犯了那个错误.请提出任何更改.我认为我的算法是写的,但如果有误,请建议任何更改.

I wanted to know if my some writing practice is making that error. Please suggest any changes. I think my algo is write but plz suggest any changes if its wrong.

这是问题的链接.

http://www.spoj.com/problems/NSTEPS/

def check_num(m,n):
    if(m!=n and m!=n+2):
        return 0;
    elif(m==n) :
        if(m%2==1):
            a=int((m+1)/2)-1;
            return (1+a*4);
        else :
            a=int(m*2);
            return(a);
    elif(m==n+2):
        if(n%2==1):
            a=int((n+1)/2)+1;
            return (3+a*4);
        else :
            a=int(n*2);
            return(2+a);            
import sys;
inp=sys.stdin.read().split("\n");
N=int(inp[0]);
i=1;
l=dict();
b=dict();
c=dict();
for i in range(1,N+1):
    a=inp[i];
    k=0;
    b[i],c[i]=[int(a[k]),int(a[k+2])];
    if (b[i]==0 and c[i]==0):
        l[i]=0;
    else :
    l[i]=check_num(b[i],c[i]);
for i in range(1,N+1):
    if (l[i]==0):
        if (c[i]==0 and b[i]==0):
            print l[i];
        else:
            print "No Number";
    else :
        print l[i];
sys.exit(0)

提前致谢.

推荐答案

基本上,当您尝试访问大于其大小的数组或对于某些测试用例您的程序可能无限运行时,您会遇到 nzec 错误或运行时错误...

Basically you get nzec error or runtime error when your trying to access the array greater then its size or for some testcases your program may be running infinitely...

最后,它们可能是您代码中的一些逻辑错误,请在您的代码中尝试极端测试用例.

At the last , their might be some logical error in your code , try extreme test case in your code .

由于在 spoj 中,该站点没有得到正确维护,对于某些问题,我尝试使用 python 和 java,但在 C 和 C++ 中获得了 AC.这发生了 bcz 问题的 setter 还没有设置正确的时间.这种事情在我身上发生过很多次.

Since in spoj , the site is not maintained properly, for some question i tried i got tle in python and java but got AC in C and C++. This happen bcz the setter of the problem has not set the correct timing. This type of things have happen a lot to me .

快乐编码

这篇关于我的 Every python 代码在 SPOJ 中提供了 NZEC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆