| ||||||||||
| 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 | |||||||||
9028K,0ms....//poj果然是在输入数据之后才计算时间的啊。
#include<iostream>
using namespace std;
const int MaxSize=500010;
const int INFINITY=7000010;
int a[MaxSize];
bool flag[INFINITY];
int main()
{
memset(flag,false,sizeof(flag));
a[0]=0;
int i;
for(i=1;i<MaxSize;i++){
if(a[i-1]-i>0 && !flag[a[i-1]-i]){
a[i]=a[i-1]-i;
flag[a[i-1]-i]=true;
}
else{
a[i]=a[i-1]+i;
flag[a[i-1]+i]=true;
}
}
int k;
while(cin>>k && k>=0) 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