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 |
用空间换时间0ms 5257kb#include<stdio.h> #include<string.h> #define Size 500000 int a[Size+5]; char exist[Size*10]; int main() { int i,k; a[0]=0; memset(a,0,sizeof(exist)); exist[0]=1; for(i=1;i<=Size;i++) { if(a[i-1]-i<=0||exist[a[i-1]-i]==1) a[i]=a[i-1]+i; else a[i]=a[i-1]-i; exist[a[i]]=1; } while(scanf("%d",&k),k!=-1) printf("%d\n",a[k]); return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator