【问题标题】:Not showing the expected output for a certain input未显示特定输入的预期输出
【发布时间】:2022-11-26 22:08:45
【问题描述】:

我写了这个问题的代码。

https://codeforces.com/contest/1744/problem/B

我的代码完全适用于下面给出的输入,

输入:

1
1 1
1
1 1

输出:

2

输入:

1
3 3
1 2 4
0 2
1 3
0 5

输出:

11
14
29

输入:

1
6 7
1 3 2 4 10 48
1 6
0 5
0 4
0 5
1 3
0 12
0 1

输出:

80
100
100
100
118
190
196

但是对于这个输入:

1
6 7
1000000000 1000000000 1000000000 11 15 17
0 17
1 10000
1 51
0 92
0 53
1 16
0 1

输出应该是这样的:

3000000094
3000060094
3000060400
3000060952
3000061270
3000061366
3000061366

但是我的代码为此代码提供了一些垃圾值或错误输出:

-1294967202
-1294967202
-1294906896
-1294906344
-1294906026
-1294905930
-1294905930

我不明白主要问题在哪里。请帮我解决这个问题。这是我的代码。如果您发现问题,请帮我解决。提前致谢..

#include<stdio.h>

int odd_even_incre(long long a[], int x, int y,int n)
{
    int i,j;
    long long sum=0;

    if(x%2==0){
        for(i=0; i<n ;i++){
            if(a[i]%2==0){
                a[i]= a[i]+y;
            }
        sum = sum+a[i];
        }
    }
    else{
        for(i=0; i<n ;i++){
            if(a[i]%2!=0){
                a[i]= a[i]+y;
            }
        sum = sum+a[i];
        }
    }
    return sum;
}

int main()
{
    int n,q,t, i,j,x,y;
    long long a[100000],result;

    scanf("%d", &t);

    for(i=0; i<t; i++)
    {
        scanf("%d %d", &n, &q);
        for(j=0 ; j<n ; j++)
        {
            scanf("%lld", &a[j]);
        }
        for (j=0; j<q; j++)
        {
            scanf("%d %d", &x, &y);
            result = odd_even_incre(a,x,y,n);
            printf("%lld\n",  result);
        }
    }

    return 0;
}

【问题讨论】:

  • 您认为该数组的大小如何?您希望适合您的函数堆栈的大小是多少?提示:“太大”和“还不够”
  • printf("%d mb of memory", ((sizeof(long long int) * 1000000000) / 1024 / 1024));
  • “没有正确接受输入”——这是什么意思?到底发生了什么?

标签: c long-integer unsigned-long-long-int long-long


【解决方案1】:

我已经修好了。这将只是

long long  odd_even_incre(){}

代替

int odd_even_incre(){}

而已。谢谢你们

【讨论】:

    猜你喜欢
    • 2014-09-19
    • 1970-01-01
    • 1970-01-01
    • 2015-07-28
    • 1970-01-01
    • 1970-01-01
    • 2021-07-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多