| ||||||||||
| 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 | |||||||||
果然是空间换时间,暴力打表,32MS#include<iostream>
#include<string>
using namespace std;
long list[500001];
bool a[30000001];
void cal(){
for(int i=0;i<30000000;i++)a[i]=false;
list[0]=0;
for(int j=1;j<500001;j++){
int tmp1=list[j-1]-j;
int tmp2=list[j-1]+j;
if(tmp1>0&&a[tmp1]==false){
list[j]=tmp1;
a[tmp1]=true;
}else {list[j]=tmp2;a[tmp2]=true;}
}
}
int main (){
int N;
cal();
cin>>N;
while(N!=-1){
cout<<list[N]<<endl;
cin>>N;
}
system("pause");
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator