Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
哈哈,打表,水过,建议后人用打表吧~#include<iostream> using namespace std; int a[500006],visit[8000000]; int main() { a[0]=0; memset(visit,0,sizeof(visit)); visit[0]=1; for(int i=1;i<=500000;i++) { if(a[i-1]-i<0) a[i]=a[i-1]+i; else { if(visit[a[i-1]-i]) a[i]=a[i-1]+i; else a[i]=a[i-1]-i; } visit[a[i]]=1; } int k; while(cin>>k&&k!=-1) { cout<<a[k]<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator