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 |
算法有点弱,但好歹16ms过了就是了#include <iostream> using namespace std; int main() { int a[500001],flag=0; char b[4000000]; int j,w; for(j=0;j<4000000;j++) { b[j]=0; } a[0]=0; int i; for(i=1;i<500001;i++) { w=a[i-1]-i; if(a[i-1]-i>0&&b[w]==0) { a[i]=a[i-1]-i; b[w]=1; } else { a[i]=a[i-1]+i; w=a[i]; b[w]=1; } } int u; cin>>u; while(u!=-1) { cout<<a[u]<<endl; cin>>u; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator