zoukankan      html  css  js  c++  java
  • poj 2081 Recaman's Sequence

    题目链接:http://poj.org/problem?id=2081

    解题思路:简单dp

     1 ///////////////////////////////////////////////////////////////////////////
     2 //problem_id: poj 2081
     3 //user_id: SCNU20102200088
     4 ///////////////////////////////////////////////////////////////////////////
     5 
     6 #include <algorithm>
     7 #include <iostream>
     8 #include <iterator>
     9 #include <iomanip>
    10 #include <cstring>
    11 #include <cstdlib>
    12 #include <string>
    13 #include <vector>
    14 #include <cstdio>
    15 #include <cctype>
    16 #include <cmath>
    17 #include <queue>
    18 #include <stack>
    19 #include <list>
    20 #include <set>
    21 #include <map>
    22 using namespace std;
    23 
    24 ///////////////////////////////////////////////////////////////////////////
    25 typedef long long LL;
    26 const double PI=acos(-1.0);
    27 ///////////////////////////////////////////////////////////////////////////
    28 
    29 ///////////////////////////////////////////////////////////////////////////
    30 //Add Code:
    31 const int maxn=500000;
    32 int a[maxn+5];
    33 bool flag[maxn*10+5];
    34 ///////////////////////////////////////////////////////////////////////////
    35 
    36 int main(){
    37     ///////////////////////////////////////////////////////////////////////
    38     //Add code:
    39     int i,k;
    40     memset(flag,0,sizeof(flag));
    41     a[0]=0,flag[0]=1;
    42     for(i=1;i<=maxn;i++){
    43         if(a[i-1]-i>0 && !flag[a[i-1]-i]){
    44             a[i]=a[i-1]-i;
    45             flag[a[i]]=1;
    46         }
    47         else{
    48             a[i]=a[i-1]+i;
    49             flag[a[i]]=1;
    50         }
    51     }
    52     while(scanf("%d",&k)!=EOF){
    53         if(k==-1) break;
    54         printf("%d
    ",a[k]);
    55     }
    56     ///////////////////////////////////////////////////////////////////////
    57     return 0;
    58 }
    59 
    60 ///////////////////////////////////////////////////////////////////////////
    61 /*
    62 Testcase:
    63 Input:
    64 7
    65 10000
    66 -1
    67 Output:
    68 20
    69 18658
    70 */
    71 ///////////////////////////////////////////////////////////////////////////
  • 相关阅读:
    Microsoft Visual Studio 2008
    JavaScript动态添加|绑定事件
    超级实的js代码大全 [转]
    《dojo 边学边用》(02), djConfig配置解说
    整合ckeditor_3.0.1和ckfinder_aspnet_1.4.1.1,配置随笔记录
    everybody is a tourist。you and me。
    测试并提升你的jQuery选择器水平
    php
    《dojo 边学边用》(01), 初识dojo,dojo简介和框架概览
    HTML 三栏自动适应
  • 原文地址:https://www.cnblogs.com/linqiuwei/p/3267326.html
Copyright © 2011-2022 走看看