博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj_2081
阅读量:3530 次
发布时间:2019-05-20

本文共 1167 字,大约阅读时间需要 3 分钟。

Recaman's Sequence
Time Limit:3000MS Memory Limit:60000K
Total Submissions:19016 Accepted:7963

Description

The Recaman's sequence is defined by a0 = 0 ; for m > 0, a
m= a
m−1− m if the rsulting a
mis positive and not already in the sequence, otherwise a
m= a
m−1+ m.
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 a
k.

Input

The input consists of several test cases. Each line of the input contains an integer k where 0 <= k <= 500000.
The last line contains an integer −1, which should not be processed.

Output

For each k given in the input, print one line containing a
kto the output.

Sample Input

710000-1

Sample Output

2018658
 
DP水题
 
#include 
#include
using namespace std;const int MAXN = 9999999;int a[MAXN];bool flag[MAXN];void DP(){ for(int i=1;i<=500000;i++) { if(a[i-1] - i > 0 && flag[a[i-1] - i] == false) { a[i] = a[i-1] - i; flag[a[i-1] - i] = true; } else { a[i] = a[i-1] + i; flag[a[i-1] + i] = true; } }}int main(){ memset(flag,false,sizeof(false)); a[0] = 0; DP(); int k; while(cin>>k) { if(k == -1) break; cout<
<

转载地址:http://etyhj.baihongyu.com/

你可能感兴趣的文章
全文检索工具elasticsearch的安装和简单介绍
查看>>
利用Kibana学习全文检索工具elasticsearch
查看>>
SpringBoot在Test测试类或自定义类中通过@Autowired注入为null
查看>>
使用docker搭建YAPI服务
查看>>
西南科技大学OJ题 邻接表到邻接矩阵1056
查看>>
西南科技大学OJ题 有向图的出度计算1057
查看>>
西南科技大学OJ题 有向图的最大出度计算1059
查看>>
西南科技大学OJ题 带权有向图计算1063
查看>>
oracle主键自增触发器编写
查看>>
String与StringBuilder与StringBuffer三者的差别
查看>>
各种IO流之间的关系和区别
查看>>
SSM如何实现上传单图片
查看>>
SSM环境下java如何实现语音识别(百度语音识别版)
查看>>
ajax方法参数的用法和他的含义
查看>>
数据库基础技巧及用法
查看>>
实用方法:无request参数时获得当前的request的方法
查看>>
JS操作数组常用实用方法
查看>>
java实现MD5多次进行加密加盐操作
查看>>
springboot实现CAS的server服务器端的搭建,并实现链接mysql数据库,自定义加密算法
查看>>
Python超详细的安装教程
查看>>