POJ 2081 Recaman's Sequence(水~)
来源:互联网 发布:雪梨淘宝店叫什么名字 编辑:程序博客网 时间:2024/05/16 09:19
Description
第m个位置的数是根据第m-1位置的数推出来的如果a[m-1]-m>0,并且a[m-1]-m在前面的序列中没有出现过那么a[m] = a[m-1]-m否则a[m] = a[m-1]+m,a[0]=0
Input
多组用例,每组一个整数m表示查询该位置的值,以m=-1结束输入
Output
对于每个查询,输出相应位置的值
Sample Input
7
10000
-1
Sample Output
20
18658
Solution
水题,开个标记数组标记a[m-1]-m是否出现过即可
Code
#include<stdio.h>int s[500010]={0},num[5000010]={0};//初始化 int main(){ int n,i,j; s[0]=0; num[0]=1;//标记数组 for(i=1;i<500010;i++)//打表 { s[i]=s[i-1]-i; if(s[i]<0||num[s[i]])//出现过 s[i]=s[i-1]+i; num[s[i]]=1;//标记 } while(scanf("%d",&n)&&n!=-1) printf("%d\n",s[n]); return 0;}
0 0
- 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 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】
- 使用doxygen排版数学公式出错的解决方法
- 自动化测试页面上对hidden控件的处理
- 通过JSTL+EL实现循环迭代
- 神马都是浮云,unity中自己写Coroutine协程源码
- C++命名空间
- POJ 2081 Recaman's Sequence(水~)
- html元素解释
- 二维码框架ZBarSDK的使用和自定义二维码扫描界面方法
- 闭包错误-Cannot invoke 'responseResult' with an argument list of type
- Invert Binary Tree
- 软件开发过程学习笔记(一)之软件开发流程
- STL - deque(双端队列)
- iOS 开发 admob 使用报错
- mysql中统计精度问题