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

POJ-2081:Recaman's Sequence

2013-01-24 14:52 309 查看
//这道题主要是记录下之前有没有出现过的。
#include<iostream>
#include<string.h>
using namespace std;
const int N = 500001;
bool vis[N*10];	//之前数组开得太小了。
long result
;

int main()
{
memset(vis,false,sizeof(vis));
memset(result,0,sizeof(result));
int i;
result[0] = 0;
for(i=1;i<N;i++)
{
if (result[i-1]-i>0 && !vis[result[i-1]-i])
{
result[i] = result[i-1] - i;
vis[result[i]] = true;
}
else
{
result[i] = result[i-1] + i;
vis[result[i]] = true;
}
}
int k;
while(cin>>k && k!=-1)
{
cout<<result[k]<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: