SPOJ上的硬币—每次遇到运行时错误(SIGSGEV)

拉曼

/ ***************************************************** ****************************************************** ************************************ SPOJ上的硬币问题。” http://www.spoj.com/problems/硬币/ “。每次我遇到运行时错误(SIGSGEV)。请帮助解决问题。它在我的机器上运行良好,我找不到任何问题。它也给出正确的输出。但是在SPOJ中,它并没有被接受。****************************************************** ****************************************************** *********************************** /

#include<stdio.h>

long long  arr[1000000]; /* Is this large number ok?*/

long long coins(long long n)/*Used recursion*/
{
    if(n==0)
        return 0;

    if(arr[n]!=0)
        return arr[n];

    long long a,b,c,sum;
    a=n/2;
    b=n/3;
    c=n/4;
    sum=coins(a)+coins(b)+coins(c);
    if(sum>n)
    {
        arr[n]=sum; /*Dynamic programming*/
        return sum;
    }
    else
    {
        arr[n]=n;   /*Dynamic programming*/
        return n;
    }
}

int main()
{
    long long n;
    while(scanf("%lld",&n))//Have doubt in this. Should it be while(scanf(...)!=EOF)
    {
    long long dollar=coins(n);
    printf("%lld\n",dollar);
    }
    return 0;
}
米基卡卡

问题表明n <= 1000000000,并且在功能硬币中,您将使用arr [n],该绝对值将超出1000000的范围。

但是我认为你是对的〜

提示:考虑2 ^ 32> 1000000000,那么有多少个子问题?

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

SPOJ上的NZEC运行时错误

SPOJ:运行时错误(NZEC)

我在PHP上运行时遇到错误

在SPOJ上获取运行时错误(SIGSEGV),无法找出我的代码有什么问题

使用C在Spoj中运行时NZEC错误

为什么我在测试仪上遇到Pytorch运行时错误

无法弄清楚我的程序在spoj而不是ideone上给出运行时错误的原因

React App 在浏览器中使用零食运行时运行良好,但在移动设备上使用 expo go 运行时遇到错误

For循环上的运行时错误13

VBA宏上的运行时错误

实现可以从蓝牙健康设备接收连续数据的代码,而我在Eclipse上遇到运行时错误。

使用Python 2.7.9的TWOSQRS SPOJ给出了运行时错误(NZEC)

Spoj 任务奖励:ARRAYSUB - subarraysZadanie 运行时错误 (NZEC) {c#}

每次运行时生成新的 UUID

每次循环运行时更改类

运行时错误13:每次我运行代码时都键入不匹配

IIS .Net运行时错误上的Googlewebauthorizationbroker.AuthorizeAsync

仅在systemd上运行时发生SSL错误

添加方法VBA上的运行时错误

在NSIndexPath上意外发现nil运行时错误

realloc() 上的运行时错误 | 中序遍历

在设备上运行时组件异常错误

在Eclipse上运行时出现rJava错误

linux mint 上的 Vega 运行时错误

简单更新查询上的运行时错误13

在Windows 10上运行时Blazegraph错误

Laravel + Vue上的随机JavaScript运行时错误

运行时错误:Range AutoFilter上为“ 1004”

使用 ElseIf / If / Else 在 VBA 上运行时错误 13