poj Recaman's Sequence 打表
来源:互联网 发布:睡大外女生知 编辑:程序博客网 时间:2024/05/17 04:44
题意:根据a[i-1] - i 大于0 并且没出现过,或者a[i-1] - i 小于0 求出序列
思路:打表 + hash 标记状态
#include<iostream>using namespace std;int a[500010];bool hash[50001000];//hash得开大点 不然RE int main() { a[0] = 0; memset(hash,0,sizeof(hash)); for (int i = 1 ; i <=500010 ; i ++) { if (a[i-1] - i > 0 && !hash[a[i-1]-i]) { a[i] = a[i-1] - i; hash[a[i]] = 1; } else { a[i] = a[i-1] + i; hash[a[i]] = 1; } } int k; while (scanf("%d",&k)!=EOF) { if (k == -1) break; printf("%d\n",a[k]); } }
- poj Recaman's Sequence 打表
- POJ 2081 Recaman's Sequence
- poj 2081 Recaman's Sequence
- POJ 2081 Recaman's Sequence
- poj 2081 :Recaman's Sequence
- poj 2081Recaman's Sequence
- poj 2081 Recaman's Sequence
- POJ 2081 Recaman's Sequence
- POJ-2081:Recaman's Sequence
- POJ-2081-Recaman's Sequence
- poj 2081 Recaman's Sequence
- POJ 2081 Recaman's Sequence
- POJ 2081 Recaman's Sequence
- POJ 2081 Recaman's Sequence
- poj 2081 Recaman's Sequence
- POJ 2081 Recaman's Sequence
- poj 2081【Recaman's Sequence】
- POJ 2081 Recaman's Sequence
- Vector模板常见操作
- poj 3750 小孩儿报数问题
- EDK下如何调整堆(heap)和栈(stack)
- windows 2008 server 安装 iis时注意事项
- 大数加法 模版
- poj Recaman's Sequence 打表
- 使用httpclient获取数据时出现中文乱码解决方法
- 软件调试系列之Windbg探究
- Android的系统架构认识
- vim的基本操作
- ubuntu11.10英文版实现中文输入的办法 (为ubuntu11.10英文版操作系统添加五笔输入法)
- 【小注意】java中字符串的replace方法使用注意
- STL学习笔记1(CArray与vector)
- CArray实现机制