Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

果然是空间换时间,暴力打表,32MS

Posted by howling at 2011-08-12 16:10:58 on Problem 2081
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator