关闭

POJ 2081 Recaman's Sequence(水~)

325人阅读 评论(0) 收藏 举报
分类:

Description
第m个位置的数是根据第m-1位置的数推出来的如果a[m-1]-m>0,并且a[m-1]-m在前面的序列中没有出现过那么a[m] = a[m-1]-m否则a[m] = a[m-1]+m,a[0]=0
Input
多组用例,每组一个整数m表示查询该位置的值,以m=-1结束输入
Output
对于每个查询,输出相应位置的值
Sample Input
7
10000
-1
Sample Output
20
18658
Solution
水题,开个标记数组标记a[m-1]-m是否出现过即可
Code

#include<stdio.h>
int s[500010]={0},num[5000010]={0};//初始化 
int main()
{
    int n,i,j;
    s[0]=0;
    num[0]=1;//标记数组 
    for(i=1;i<500010;i++)//打表 
    {
        s[i]=s[i-1]-i;
        if(s[i]<0||num[s[i]])//出现过 
            s[i]=s[i-1]+i;
        num[s[i]]=1;//标记 
    }
    while(scanf("%d",&n)&&n!=-1)
        printf("%d\n",s[n]);
    return 0;
}
0
0
查看评论

POJ2081:Recaman's Sequence

Description The Recaman's sequence is defined by a0 = 0 ; for m > 0, am = am−1 − m if the rsulting am is positive and not already in the seque...
  • libin56842
  • libin56842
  • 2014-03-01 21:51
  • 2800

poj 2081 Recaman's Sequence

开始还以为暴力做不出来,需要找规律,找了半天找不出来,原来直接暴力。。 代码如下: #include int a[1000050]; int b[100000000]={0}; int main() { int i,k; a[0]=0; for(i=1;i<=500000;...
  • lihaogegehuting
  • lihaogegehuting
  • 2014-07-22 16:45
  • 711

poj 2081【Recaman's Sequence】

Description The Recaman's sequence is defined by a0 = 0 ; for m > 0, a m = a m−1 − m if the rsulting a m is ...
  • u012970471
  • u012970471
  • 2015-04-14 11:01
  • 402

poj 2081 Recaman's Sequence

Recaman's Sequence Time Limit: 3000MS   Memory Limit: 60000K Total Submissions: 22529   Accepted: ...
  • Z_huing
  • Z_huing
  • 2016-05-11 18:37
  • 183

POJ 2081 Recaman's Sequence

Description The Recaman's sequence is defined by a0 = 0 ; for m > 0, am = am−1 − m if the rsulting am is positive and not a...
  • Misdom_Tian_Ya
  • Misdom_Tian_Ya
  • 2015-03-17 17:45
  • 263

poj 2081 :Recaman's Sequence

依然说:这题是用空间换时间! #include using namespace std; int seq[500005]; bool vis[3200005]; int main() { int num; seq[0]=0; memset(vis,
  • softliumin
  • softliumin
  • 2011-08-02 20:47
  • 245

POJ 2081 Recaman's Sequence

题目链接: http://poj.org/problem?id=2081 Description The Recaman's sequence is defined by a0 = 0 ; for m > 0, am = am−1 − m if the rsulting a...
  • gemire
  • gemire
  • 2014-03-01 14:44
  • 402

POJ 2081——Recaman's Sequence

Recaman's Sequence Time Limit: 3000MS   Memory Limit: 60000K Total Submissions: 22885   Accepted: 9881 Des...
  • LDUtyk
  • LDUtyk
  • 2016-09-04 12:43
  • 365

POJ 2081 Recaman's Sequence

map水过2400ms+懒得改成hash了   Description The Recaman's sequence is defined by a0 = 0 ; for m > 0, am = am−1 − m if the rsulting am is positi...
  • zck921031
  • zck921031
  • 2012-06-30 15:31
  • 346

2081 Recaman's Sequence

<br />Recaman's SequenceTime Limit:3000msMemory limit:60000kB题目描述The Recaman's sequence is defined by a0 = 0 ; for m > 0, am = a...
  • kongming_acm
  • kongming_acm
  • 2010-07-11 09:54
  • 572
    个人资料
    • 访问:550342次
    • 积分:24514
    • 等级:
    • 排名:第317名
    • 原创:1943篇
    • 转载:0篇
    • 译文:0篇
    • 评论:68条
    最新评论