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

水一下

Posted by chenjiang at 2009-08-24 16:01:40 on Problem 2081
/*
  Name: 
  Copyright: 
  Author: chenjiang
  Date: 24-08-09 15:50
  Description: 
*/
#include<iostream>
using namespace std;

bool p[5000000];
int a[500001];
int main()
{    int i,n;
     p[0]=1;a[0]=0;
     memset(p,0,sizeof(p));
     for(i=1;i<=500000;i++)
     {   if(a[i-1]-i>0&&p[a[i-1]-i]==0)
         {  a[i]=a[i-1]-i;p[a[i]]=1;  }
         else
         {   a[i]=a[i-1]+i;p[a[i]]=1;
         }
     }
     while(cin>>n)
     {   if(n==-1)break;
         cout<<a[n]<<endl;
     }
     system("pause");
     return 0;
}
/*
7
20
10000
18658
500000
626684
-1
*/

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