Poj 2081 Recaman's Sequence之解题报告
Time Limit: 3000MS | Memory Limit: 60000K | |
Total Submissions: 22363 | Accepted: 9605 |
Description
The first few numbers in the Recaman's Sequence is 0, 1, 3, 6, 2, 7, 13, 20, 12, 21, 11, 22, 10, 23, 9 ...
Given k, your task is to calculate ak.
Input
The last line contains an integer −1, which should not be processed.
Output
Sample Input
7
10000
-1
Sample Output
28
18658
对于这题的正确做法就是模拟加暴力Dp;
在DP的时候一定记得考虑时间复杂度的问题;
代码:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring> using namespace std; const int maxn = +;
int a[maxn];
bool used[]; int main(void)
{
int k,i,j; a[] = ;
memset(used,,sizeof(used));
used[] = ;
for(i=;i<=;++i)
{
if(a[i-]-i>&&!used[a[i-]-i]) a[i] = a[i-]-i;
else a[i] = a[i-]+i;
used[a[i]] = ;
}
while(scanf("%d",&k),k!=-)
{ cout<<a[k]<<endl;
} return ;
}
Poj 2081 Recaman's Sequence之解题报告的更多相关文章
- 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 ...
- poj 2081 Recaman's Sequence
開始还以为暴力做不出来,须要找规律,找了半天找不出来.原来直接暴力.. 代码例如以下: #include<stdio.h> int a[1000050]; int b[100000000] ...
- POJ 2081 Recaman's Sequence(水的问题)
[简要题意]:这个主题是很短的叙述性说明.挺easy. 不重复. [分析]:只需要加一个判断这个数是否可以是一个数组,这个数组的范围. // 3388K 0Ms #include<iostrea ...
- poj 2284 That Nice Euler Circuit 解题报告
That Nice Euler Circuit Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 1975 Accepted ...
- poj 1094 Sorting It All Out 解题报告
题目链接:http://poj.org/problem?id=1094 题目意思:给出 n 个待排序的字母 和 m 种关系,问需要读到第 几 行可以确定这些字母的排列顺序或者有矛盾的地方,又或者虽然具 ...
- Poj 1953 World Cup Noise之解题报告
World Cup Noise Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 16369 Accepted: 8095 ...
- POJ 1308 Is It A Tree? 解题报告
Is It A Tree? Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 32052 Accepted: 10876 D ...
- POJ 1958 Strange Towers of Hanoi 解题报告
Strange Towers of Hanoi 大体意思是要求\(n\)盘4的的hanoi tower问题. 总所周知,\(n\)盘3塔有递推公式\(d[i]=dp[i-1]*2+1\) 令\(f[i ...
随机推荐
- What we learned in Seoul with AlphaGo
What we learned in Seoul with AlphaGo March 16, 2016 Go isn’t just a game—it’s a living, breathing c ...
- office安装不了 “windows installer 服务不能更新一个或多个受保护的windows文件”
出现这种情况可能是系统中某些文件缺失了,一般发生于安装GHOST版或做过精简的系统 打开C:\WINDOWS\msagent 看看文件夹中内容是不是如下图所示: 再打开C:\Program Files ...
- 破解之寻找OEP[手动脱壳](1)
OEP:(Original Entry Point),程序的入口点,软件加壳就是隐藏了OEP(或者用了假的OEP), 只要我们找到程序真正的OEP,就可以立刻脱壳. PUSHAD (压栈) 代表程序的 ...
- "Principles of Reactive Programming" 之 <Persistent Actor State>学习笔记
这是<Pinciples of Reactive Programming>week6的最后一课. 为什么需要把actor的状态持久化? 如果actor没有状态,那么在任何实时,这个acto ...
- spark storage之SparkEnv
此文旨在对spark storage模块进行分析,整理自己所看所得,等以后再整理. ok,首先看看SparkContext中sparkEnv相关代码: private[spark] def creat ...
- 如何在Ubuntu下搭建Android NDK开发环境
1 搭建Android SDK开发环境 参考在在Ubuntu下搭建Android SDK开发环境(图文)首先在Ubuntu下搭建Android SDK开发环境. 2 下载NDK开发包 打开官网: ht ...
- hdu 4559 涂色游戏 博弈论
构造SG函数:sg[i]表示2*i的sg值!! 代码如下: #include<iostream> #include<stdio.h> #include<algorithm ...
- codeforces #309 div1 D
求最小值最大显然是要二分 二分之后转换成了判定性问题 我们考虑哪些点一定不能选 显然是将所有可选点选中之后依然不满足条件的点不能选 那么我们不妨维护一个堆,每次取出堆顶看看是否满足条件 不满足条件就p ...
- 每个QWidget都有contentsMargins函数,善用QMargins
m_pSearchLineEdit = new QLineEdit(); QPushButton *pSearchButton = new QPushButton(this); pSearchButt ...
- POJ1068——Parencodings
Parencodings Description Let S = s1 s2...s2n be a well-formed string of parentheses. S can be encode ...