| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 979 人关注过本帖
标题:编译出现runtime error的提示,望解答
取消只看楼主 加入收藏
MJFW
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2008-12-3
收藏
 问题点数:0 回复次数:0 
编译出现runtime error的提示,望解答
题目:
  Recaman's Sequence
Time Limit:3000MS  Memory Limit:60000K
Total Submit:1656 Accepted:533

Description
The Recaman's sequence is defined by a0 = 0 ; for m > 0, am = am 1   m if the rsulting am is positive and not already in the sequence, otherwise am = am 1 + m.
The first few numbers in the Recaman's Sequence is 0, 1, 3, 6, 2, 7, 13, 20, 12, 21, 11, 22, 10, 23, 9 ...
Given k, your task is to calculate ak.

Input
The input consists of several test cases. Each line of the input contains an integer k where 0 <= k <= 500000.
The last line contains an integer  1, which should not be processed.

Output
For each k given in the input, print one line containing ak to the output.

Sample Input


7
10000
-1

Sample Output


20
18658

我写的源代码:
#include<iostream>
using namespace std;
void process(long n)
{
    long *a,*b,k,temp;
    a=new long[500001];
    b=new long[3011600];
    a[0]=0;
    b[0]=1;
    for(k=1;k<=n;k++)
    {
        temp=a[k-1]-k;
        if(temp>0)
        {
            if(b[temp]==1)
            {
                a[k]=a[k-1]+k;
                b[a[k]]=1;
            }
            else
            {
                a[k]=a[k-1]-k;
                b[temp]=1;
            }
        }
        else
        {
            a[k]=a[k-1]+k;
            b[a[k]]=1;
        }
    }
    
    cout<<a[k-1]<<endl;
    delete []a;
    delete []b;
}
int main(void)
{
    int i=-1,j;
    long n,math[100];
    do
    {
        i++;
        cin>>math[i];
        if(math[i]<-1||math[i]>500000)
        {i--;}
    }while(math[i]!=-1);
    for(j=0;j<i;j++)
    {
        n=math[j];
        process(n);
    }
    return 0;
}
结果在下面这个网站上提交编译时说Runtime Error,这题的题号是:2081
http://ai.pku.
搜索更多相关主题的帖子: runtime 提示 解答 
2008-12-03 23:20
快速回复:编译出现runtime error的提示,望解答
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.082539 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved