POJ 2081 Recaman's Sequence
来源:互联网 发布:python 字符串连接数字 编辑:程序博客网 时间:2024/05/16 11:13
题目链接:http://poj.org/problem?id=2081
分析:就是要求一系列数字,如果a[i-1]-i>0 则:ai=a[i-1]-i,否则的话 ai=a[i-1]+i,同时要满足这些数字在之前没有出现过。
源代码:
//POJ 2081 AC#include <iostream>using namespace std;int a[500010];bool flag[3500000]={false};//如果也开个500010 运行时错误 void init(){ int i,t; a[0]=0; for(i=1;i<=500000;i++){ t=a[i-1]-i; if(t>0&&!flag[t]){ a[i]=t; } else{ a[i]=a[i-1]+i; } flag[a[i]]=true; }}int main(){ int k; init(); while(cin>>k){ if(k==-1) break; cout<<a[k]<<endl; } return 0;}
- 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
- POJ-2081 Recaman's Sequence
- HTML5的学习(一)
- DataSet和DataReader的区别
- Flash Builder非法关闭造成无法启动的解决方法
- windows.event.srcElement和event.target含义的介绍
- rails routes
- POJ 2081 Recaman's Sequence
- 【转】J2SE5中的最新注释功能SuppressWarnings
- JMS学习笔记2
- euca2ool无法访问cloud解决方法
- Android得不到对话框中EditView值的问题
- The investigations about XXX network character support
- 图像拼接技术分类
- 关于重写equals,hashcode以及compareTo方法
- 基于HTK的语音拨号系统