http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1421

题目大意:

定义a^m为 a^m = a^(m-1) - m  如果a^m 为正且没有出现过。否则a^m = a^(m-1) + m 。给你k,让你求a^k

思路:

打表。

k最大为50万,而a[500000]<63万,故我们开个数组记录是否出现过即可。

#include<cstdio>
const int MAXK=500000+2;
const int MAXN=630000;
int a[MAXK];
bool exist[MAXN]={0};
int main()
{
a[0]=0;
exist[0]=1;
for(int i=1;i<MAXK;i++)
{
if(a[i-1]-i>0 && !exist[ a[i-1]-i ])
a[i]=a[i-1]-i;
else
a[i]=a[i-1]+i;
exist[ a[i] ]=1;
}
//printf("%d\n",a[500000]); 62W
int k;
while(~scanf("%d",&k),k!=-1)
{
printf("%d\n",a[k]);
}
return 0;
}

ZOJ 2421 Recaman's Sequence的更多相关文章

  1. Poj 2081 Recaman's Sequence之解题报告

                                                                                                         ...

  2. POJ-2081 Recaman's Sequence

    Recaman's Sequence Time Limit: 3000MS Memory Limit: 60000K Total Submissions: 22392 Accepted: 9614 D ...

  3. POJ 2081 Recaman's Sequence

    Recaman's Sequence Time Limit: 3000ms Memory Limit: 60000KB This problem will be judged on PKU. Orig ...

  4. poj 2081 Recaman's Sequence (dp)

    Recaman's Sequence Time Limit: 3000MS   Memory Limit: 60000K Total Submissions: 22566   Accepted: 96 ...

  5. zoj 3672 Gao The Sequence

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4915题意:a[k]-一个任意的数,这个数要等于a[1]~a[k]每个数减去任意 ...

  6. 【ZOJ 4060】Flippy Sequence

    [链接] 我是链接,点我呀:) [题意] [题解] 按照两个区间的排列方式 我们可以分成以下几种情况 会发现这两个区间的作用 最多只能把两段连续不同的区间变为相同. 那么写个for处理出连续不相同的一 ...

  7. Recaman's Sequence_递推

    Description The Recaman's sequence is defined by a0 = 0 ; for m > 0, am = am−1 − m if the rsultin ...

  8. ZOJ Monthly, November 2012

    A.ZOJ 3666 Alice and Bob 组合博弈,SG函数应用 #include<vector> #include<cstdio> #include<cstri ...

  9. HOJ题目分类

    各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...

随机推荐

  1. 操作系统 linux 内核的三种进程调度方法

    1.SCHED_OTHER 分时调度策略: 2.SCHED_FIFO 实时调度策略.先到先服务: 3,SCHED_RR 实时调度策略,时间片轮转 . 实时进程将得到优先调用,实时进程依据实时优先级决定 ...

  2. js插件---datatables如何使用

    js插件---datatables如何使用 一.总结 一句话总结:a.引入css和js(不要忘记css):b.js代码启动插件(里面可以用参数控制各种功能) 1.dataTables如何显示控制行(比 ...

  3. cache -- clear( 缓存清除的方法)

    一:meta方法 <META HTTP-EQUIV="pragma" CONTENT="no-cache"> <META HTTP-EQUIV ...

  4. BZOJ 2037 区间DP

    跟POJ 3042是一个类型的http://blog.csdn.net/qq_31785871/article/details/52954924 思路: 先排个序 (把初始位置也插进去) f[i][j ...

  5. dp之完全背包 hdu--2159一维数组做法

    #include <iostream>#include <stdio.h>#include <string.h>using namespace std;int ma ...

  6. aop 中joinpoint的使用方法

    一.簡述下joinpoint在不同情況下的不同: 1.在around中可以用,此時可以執行被包裹的代碼,可以根據情況來判斷是否執行被包裹的代碼,以實現控制的作用. public void around ...

  7. svn: Can&#39;t convert string from &#39;UTF-8&#39; to native encoding 解决的方法

    今天在down代码时遇到了例如以下问题: [xxx@xxx ~]$ svn co https://xxxxxxxxxxxxx svn: Can't convert string from 'UTF-8 ...

  8. resource-color 的引用

    1.在xml文件中引用 android:textColor="@color/tv_top_title_color" 2.在代码中引用 1)在color.xml中定义 <?xm ...

  9. js配合My97datepicker给日期添加天数

    <input name="ctl00$ContentPlaceHolder1$txtTimeStart" type="text" value=" ...

  10. Linux下读写芯片的I2C寄存器

    要想在Linux下读写芯片的I2C寄存器,一般需要在Linux编写一份该芯片的I2C驱动,关于Linux下如何编写I2C驱动,前一篇文章<手把手教你写Linux I2C设备驱动>已经做了初 ...