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 |
机子上跑不过,都能AC!!!!!#include <iostream> using namespace std; int main() { int a[500001] = {0}; a[0] = 0; bool b[4000000] = {false}; int temp; for( int i = 1; i <= 500000; i++ ) { temp = a[i-1] - i; if( temp <= 0 || b[temp] == true ) a[i] = a[i-1] + i; else a[i] = a[i-1] - i; b[a[i]] = true; } int k; while( scanf( "%d", &k ) ) { if( k == -1 ) break; 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