Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

为什么老是runtime error,快崩溃了,谁能告诉我why

Posted by csuyuanxing at 2010-04-30 02:38:39 on Problem 2081
#include <iostream>
using namespace std;
#define MAX 50000+10

#define INFINITY 7000010 //标志数组代替循环 

int a[MAX+1];

bool exist[INFINITY];
int main()
{
    memset(exist,false,sizeof(exist));
    
    exist[0]=true;
    a[0]=0;
    
    for(int i=1;i<MAX;i++)
    {
       if(a[i-1]-i>0 && false==exist[a[i-1]-i])
        a[i]=a[i-1]-i;
       else
        a[i]=a[i-1]+i;
       
       exist[a[i]]=true;       
    }
    
    int k;
    while(1==scanf("%d",&k)&&k>=0)
    {
                                   
      printf("%d\n",a[k]); 
                                   
    }
    
    return 0;
    
}


Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator