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

Re:为什么呢?

Posted by 1030202872 at 2010-08-01 22:27:42 on Problem 2081
In Reply To:为什么呢? Posted by:1030202872 at 2010-08-01 22:26:27
代码如下:
为什么flag开50000000就AC,而5000000就RE呢
#include <iostream>
using namespace std;
int dp[500010];
char flag[50000000]={0};
int main()
{
 int i,num;
 dp[0]=0;
 flag[0]=1;
 for(i=1;i<500010;i++)
 {
   if(dp[i-1]-i>=0&&flag[dp[i-1]-i]==0)
   {
    dp[i]=dp[i-1]-i;
    flag[dp[i]]=1;
   }
   else
   {
    dp[i]=dp[i-1]+i;
   flag[dp[i]]=1;
   }
 }
 while( cin>>num&&num!=-1)
 {
   cout<<dp[num]<<endl;
 }
 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