POJ 2081 Recaman's Sequence
Recaman's Sequence
This problem will be judged on PKU. Original ID: 2081
64-bit integer IO format: %lld Java class name: Main
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
20
18658
Source
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <set>
#include <map>
#include <queue>
#include <ctime>
#define LL long long
#define INF 0x3f3f3f3f
#define pii pair<int,int> using namespace std;
const int maxn = ;
int dp[maxn];
bool vis[];
struct node {
int k,ans,o;
};
node inp[];
bool cmp1(const node &x,const node &y) {
return x.k < y.k;
}
bool cmp2(const node &x,const node &y) {
return x.o < y.o;
}
int main() {
int tot = ,tmp,cnt;
for(int i = ; i < maxn; ++i) {
dp[i] = dp[i-]-i;
if(dp[i] <= || vis[dp[i]])
dp[i] = dp[i-]+i;
vis[dp[i]] = true;
}
while(~scanf("%d",&tmp)&&(~tmp)) {
inp[tot].k = tmp;
inp[tot].o = tot++;
}
sort(inp,inp+tot,cmp1);
for(int i = cnt = ; i < maxn; ++i)
while(i == inp[cnt].k) inp[cnt++].ans = dp[i];
sort(inp,inp+tot,cmp2);
for(int i = ; i < tot; ++i)
printf("%d\n",inp[i].ans);
return ;
}
POJ 2081 Recaman's Sequence的更多相关文章
- Poj 2081 Recaman's Sequence之解题报告
...
- 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-2081 Recaman's Sequence
Recaman's Sequence Time Limit: 3000MS Memory Limit: 60000K Total Submissions: 22392 Accepted: 9614 D ...
- POJ 1019:Number Sequence 二分查找
Number Sequence Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 36013 Accepted: 10409 ...
- POJ 题目1141 Brackets Sequence(区间DP记录路径)
Brackets Sequence Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 27793 Accepted: 788 ...
- POJ 3017 Cut the Sequence
[题目链接] $O(n^2)$ 效率的 dp 递推式:${ dp }_{ i }=min\left( dp_{ j }+\overset { i }{ \underset { x=j+1 }{ max ...
- 欧拉函数 & 【POJ】2478 Farey Sequence & 【HDU】2824 The Euler function
http://poj.org/problem?id=2478 http://acm.hdu.edu.cn/showproblem.php?pid=2824 欧拉函数模板裸题,有两种方法求出所有的欧拉函 ...
随机推荐
- hiho151周*
题目链接 题目大意:依次在给定的三维坐标上垒方块,对于一个新的坐标需满足两个条件 1:六个方向有相邻的方块或者z==1[题目说明了初始状态是:所有z==0的位置都有方块] 2:该位置存在一条到无穷远处 ...
- CSS3-----transform 转换
transforn 可以转换元素,其中主要属性有:rotate() / skew() / scale() / translate()以下4种. transform:rotate():旋转:其中“de ...
- C# 打开文件 保存文件
string path = @"C: \Users\users\Desktop\xxxx.txt";// 文件路径 FileStream filestream = new File ...
- checkbox控制显示隐藏
显示文本框<input type = "checkbox" id="checkbox" onclick="on_hide();"/&g ...
- 常用的字符串方法 String ;
字符串: 1,str.charAt(num);//根据下标查找字符串中对应的字符,返回对应下标的字符; 2,str.charCodeAt(num);//字符串中下标对应的那位字符的 Unicode ...
- 永远不要在MySQL中使用“utf8”
最近我遇到了一个 bug,我试着通过 Rails 在以“utf8”编码的 MariaDB 中保存一个 UTF-8 字符串,然后出现了一个离奇的错误: Incorrect string value: ‘ ...
- vmware vsphere出现“需要整合虚拟机磁盘”的告警处理方法(完整版)
vmware vsphere出现“需要整合虚拟机磁盘”的告警 处理步骤: 1.选择对应虚机,快照——整合 (不行看下一条) 通常情况执行完第一步就好了 2.如果整合报错,提示文件锁定 2.1 新建快照 ...
- red hat linux之Samba、DHCP、DNS、FTP、Web的安装与配置
本教程是在red hat linux 6.0环境下简单测试!教程没有图片演示,需要具有一定Linux基础知识,很多地方的配置需要根据自己的情况修改,照打不一定可以配置成功.(其他不足后续修改添加) y ...
- vue-cli解析
前言 这段时间,算是空出手来写几篇文章了.由于很久都没有时间整理现在所用的东西了,所以,接下来会慢慢整理出一些文档来记录前段时间的工作和生活. 这篇文章的主题是vue-cli的理解.或许,很多人在开发 ...
- C语言计算字符串数组中每个字符串出现的个数
unsigned int str_num(char *str[], int num[], int len) { int i, j; int count; int flag[len]; ; i < ...