poj2081 Recaman's Sequence(简单递推)

来源:互联网 发布:淘宝代销发货退货地址 编辑:程序博客网 时间:2024/06/05 02:14

poj2081

需要把标记数组开大开大开大!

#include<iostream>#include<algorithm>#include<cstdio>#include<cstdlib>#include<cstring>using namespace std;const int N=500005;bool temp[10*N];int a[N];int main(){    memset(temp,false,sizeof(temp));    memset(a,0,sizeof(a));    a[0]=0;    temp[0]=true;    for(int i=1;i<N;i++)    {        if(a[i-1]-i>0&&temp[a[i-1]-i]==false)        {            a[i]=a[i-1]-i;            temp[a[i]]=true;        }        else        {            a[i]=a[i-1]+i;            temp[a[i]]=true;        }    }    int n;    while(scanf("%d",&n)!=-1)    {        if(n==-1) break;        else printf("%d\n",a[n]);;    }    return 0;}


0 0
原创粉丝点击