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[5000010]={0}; int b[5000010]={0}; int main() { a[0]=0; b[0]=-1; int i,x; for(i=1;i<500010;i++) { a[i]=a[i-1]-i; if(a[i]<0||b[a[i]]==-1) a[i]=a[i-1]+i; b[a[i]]=-1; } while(cin>>x) { if(x==-1)break; cout<<a[x]<<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