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 欧拉函数模板裸题,有两种方法求出所有的欧拉函 ...
随机推荐
- 虚拟机CentOS6.8下安装JDK
CentOS6.8下 首先下载JDK,执行命令如下: wget http://download.oracle.com/otn-pub/java/jdk/8u172-b11/a58eab1ec24242 ...
- 3ds Max制作妄想中的外星人形象
来源:CG游 作者:FedericoScarbini 使用软件:3ds Max, Photoshop, ZBrush 简介 我认为每一个人都曾经在他的人生中的某些时刻妄想着关于外星人的事情;我猜这是很 ...
- Dropout 下(关于《Dropout: A Simple way to prevent neural networks from overfitting》)
先上菜单: 摘要: Deep neural nets with a large number of parameters are very powerful machine learning syst ...
- 【模板】多项式乘法 NTT
相对来说是封装好的,可以当模板来用. #include <bits/stdc++.h> #define maxn 5000000 #define G 3 #define ll long l ...
- 路飞学城Python-Day15
模拟实现一个ATM + 购物商城程序 额度 15000或自定义 实现购物商城,买东西加入 购物车,调用信用卡接口结账 可以提现,手续费5% 支持多账户登录 支持账户间转账 记录每月日常消费流水 提供还 ...
- 简洁的MVC思想框架——Nancy(Session的使用)
前文提到关于Nancy中GET和POST以及外部引用图片,css和JS的文件等操作.今天所讲的是Nancy关于Session相关操作. Session作为web开发中极其重要的一部分,而Nancy中S ...
- Linux常用软件tree,autojump,lrzsz安装
tree安装 1.获取压缩文件 wget http://mama.indstate.edu/users/ice/tree/src/tree-1.7.0.tgz 2.解压缩 tar -zxvf tree ...
- 紫书 例题8-13 UVa 11093 (反证法)
这道题发现一个性质就解决了 如果以i为起点, 然后一直加油耗油, 到p这个地方要去p+1的时候没油了, 那么i, i+1, --一直到p, 如果以这些点 为起点, 肯定也走不完. 为什么呢? 用反证法 ...
- Python学习简单练习-99乘法表
__author__ = 'ZFH'#-*- coding:utf-8 -*-for i in range(10): #外层循环,range(10),1-9 for j in range(1,i+1) ...
- 工作笔记5.JAVA图片验证码
本文主要内容为:利用JAVA图片制作验证码. 设计思路: 1.拷贝AuthImageServlet.class图片验证码 2.配置web.xml 3.JSP中,调用封装好的AuthImageServl ...