ZOJ 2421 Recaman's Sequence
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的更多相关文章
- Poj 2081 Recaman's Sequence之解题报告
...
- POJ-2081 Recaman's Sequence
Recaman's Sequence Time Limit: 3000MS Memory Limit: 60000K Total Submissions: 22392 Accepted: 9614 D ...
- POJ 2081 Recaman's Sequence
Recaman's Sequence Time Limit: 3000ms Memory Limit: 60000KB This problem will be judged on PKU. Orig ...
- poj 2081 Recaman's Sequence (dp)
Recaman's Sequence Time Limit: 3000MS Memory Limit: 60000K Total Submissions: 22566 Accepted: 96 ...
- zoj 3672 Gao The Sequence
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4915题意:a[k]-一个任意的数,这个数要等于a[1]~a[k]每个数减去任意 ...
- 【ZOJ 4060】Flippy Sequence
[链接] 我是链接,点我呀:) [题意] [题解] 按照两个区间的排列方式 我们可以分成以下几种情况 会发现这两个区间的作用 最多只能把两段连续不同的区间变为相同. 那么写个for处理出连续不相同的一 ...
- Recaman's Sequence_递推
Description The Recaman's sequence is defined by a0 = 0 ; for m > 0, am = am−1 − m if the rsultin ...
- ZOJ Monthly, November 2012
A.ZOJ 3666 Alice and Bob 组合博弈,SG函数应用 #include<vector> #include<cstdio> #include<cstri ...
- HOJ题目分类
各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...
随机推荐
- html5中的容器标签和文本标签
html5中的容器标签和文本标签 html中的容器级标签和文本级标签,css中的块级元素和行内元素是我们常常拿来比较的四个名词(行内块级暂时先不考虑). 容器标签 容器级的标签可以简单的理解为能嵌套其 ...
- 缓存函数memorize
function mulity(x){ return x*x; } function memorize(f){ var cache = {}; var key = arguments.length + ...
- 你必须要知道的几个CSS技巧
有些经典的CSS技巧,我们还是需要记住的,这样可以节省我们大量的时间,下面零度就为大家推荐几个比较好的CSS技巧: 1.在不同页面上使用同样的导航代码 许多网页上都有导航菜单,当进入某页时,菜单上相应 ...
- js全局的解析与执行过程
先看下面实例的执行结果: alert(a);//undefined alert(b);//报错 alert(f);//输出f函数字符串 alert(g);//undefined var a = 1; ...
- spring boot 热启动
spring boot热启动有两种方式 1. 以Maven插件的形式去加载,所以启动时使用通过Maven命令mvn spring-boot:run启动,而通过Application.run方式启动的会 ...
- python生成md5, shell生成md5
echo -n 'aaa'|md5sum|cut -d ' ' -f1 python用hashlib md5=hashlib.md5(mid.upper()).hexdigest().upper()
- js--07 编解码,eval
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stri ...
- jodd-cache集锦
Jodd cache提供了一组cache的实现,其层次如下: 其中, AbstractCacheMap是一个具有计时和大小的缓存map的默认实现,它的实现类必须: 创建一个新的缓存map. 实现自己的 ...
- C# Find() 与 FindAll()方法的使用
Find() :检索与指定匹配的第一个元素 FindAll() : 检索与指定匹配的所有元素 如:List<string> strList=new List<string&g ...
- asp.net 前后台数据交互方式(转)
https://blog.csdn.net/luckyrass/article/details/38758007 一.前台直接输出后台传递的数据 后台代码: // .aspx.cs public st ...