【问题标题】:Codechef problem ISHVALA(the promised land)Codechef问题ISHVALA(应许之地)
【发布时间】:2020-06-17 09:52:14
【问题描述】:

在我的程序中什么是逻辑错误, 我不明白请帮助我,,,我尝试了不同的测试用例,,我发现所有正确.... 但在 Codechef 中,答案是错误的。

#include<iostream>
using namespace std;
int main()
{
    int T,N,M;
    cin>>T;
    while(T)
    {
        cin>>N>>M;
        int X,Y,S,c=0,d=0,i1=0,j1=0;
        cin>>X>>Y>>S;
        int x[X],y[Y];
        if(X)
        {
            for(int i=0;i<X;i++)
               cin>>x[i];
        }
        if(Y)
        {
            for(int i=0;i<Y;i++)
               cin>>y[i];
        }
        for(int i=1;i<=N;i=i+S)
        {
            for(int j=1;j<=M;j=j+S)
            {
                for(int k=0;k<X;k++)
                {
                    if(i<=x[k] && i+S-1>=x[k])
                    {
                    c=1;
                        i1=i-S+1;
                    }
                }
                    for(int k=0;k<Y;k++)
                {
                    if(j<=y[k] && j+S-1>=y[k] )
                    {
                c=1;
                    j1=j-S+1;
                    }
                }
                if(c==0  && i+S-1<=N && j+S-1<=M)
                {
                    d++;
                }
                c=0;

                if(j1)
                j=j1;
                j1=0;
            }
            if(i1)
            i=i1;
            i1=0;
        }

        cout<<d<<endl;
        T--;
    }
}

Codechef 初学者的程序(问题)。

链接在这里-enter link description here

【问题讨论】:

  • 我知道有不同的方法。但是我不明白我的代码有什么问题......

标签: c++ logic


【解决方案1】:

试试这个:

 #include<iostream>
    #define gc getchar_unlocked
    using namespace std;

void fs(int &x)
{
    register int c=gc();
    x=0;
    for(;c<48||c>57;c=gc());
    for(;c>47&&c<58;c=gc())
        x=(x<<1)+(x<<3)+c-48;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t,n,m,s,x,y,sum1,sum2,a,b;
    fs(t);
    while(t--)
    {
        fs(n);
        fs(m);
        fs(x);
        fs(y);
        fs(s);
        sum1=0;
        sum2=0;
        a=0;
        while(x--)
        {
            fs(b);
            sum1=sum1+(b-a-1)/s;
            a=b;
        }
        sum1=sum1+(n-a)/s;

【讨论】:

    猜你喜欢
    • 2021-01-01
    • 2018-02-20
    • 1970-01-01
    • 2016-10-01
    • 1970-01-01
    • 2023-04-01
    • 2019-06-10
    • 1970-01-01
    • 2010-11-19
    相关资源
    最近更新 更多