您的位置:首页 > 产品设计 > UI/UE

poj2081 Recaman's Sequence(简单递推)

2017-04-26 14:17 288 查看
poj2081

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

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
const int N=500005;
bool temp[10*N];
int a
;
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
);;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: