POJ 2081 Recaman's Sequence(水题)

【题意简述】:这个题目描述很短,也很简单。不再赘述。

【分析】:只需再加一个判别这个数是否出现的数组即可,注意这个数组的范围!

// 3388K 0Ms
#include<iostream>
using namespace std;
#define Max 500001
int a[Max];
bool b[10000000] = {false};  // b的数据范围是可以试出来的… 

void init()
{
	a[0] = 0;
	b[0] = true;
	for(int m = 1;m<Max;m++)
	{

		a[m] = a[m-1]-m;
		if(a[m]<0||b[a[m]])
		{
			a[m] = a[m-1] + m;
		}
		else{
			a[m] = a[m-1] - m;
		}
		b[a[m]] = true;
	}
}

int main()
{
	init();
	int k;
	while(cin>>k)
	{
		if(k == -1)
			break;
		cout<<a[k]<<endl;
	}
	return 0;
}

POJ 2081 Recaman's Sequence(水题)

时间: 2024-10-13 20:00:58

POJ 2081 Recaman's Sequence(水题)的相关文章

POJ 2081 Recaman&#39;s Sequence

比较简单,加一个B数组判重即可 Recaman's Sequence Time Limit: 3000MS   Memory Limit: 60000K Total Submissions: 21743   Accepted: 9287 Description The Recaman's sequence is defined by a0 = 0 ; for m > 0, am = am−1 − m if the rsulting am is positive and not already i

poj 2081 Recaman&#39;s Sequence (dp)

Recaman's Sequence Time Limit: 3000MS   Memory Limit: 60000K Total Submissions: 22566   Accepted: 9697 Description The Recaman's sequence is defined by a0 = 0 ; for m > 0, am = am−1 − m if the rsulting am is positive and not already in the sequence,

POJ 2081 Recaman&amp;#39;s Sequence(水的问题)

[简要题意]:这个主题是很短的叙述性说明.挺easy. 不重复. [分析]:只需要加一个判断这个数是否可以是一个数组,这个数组的范围. // 3388K 0Ms #include<iostream> using namespace std; #define Max 500001 int a[Max]; bool b[10000000] = {false}; // b的数据范围是能够试出来的- void init() { a[0] = 0; b[0] = true; for(int m = 1;

poj 杂题 - 2081 Recaman&#39;s Sequence

这道题目一开始就能知道考点在如何缩短查找时间.所以加快查找是我们的重点.但是在大数据面前,查找算法都不够快,所以我们用简单的hash思想来做. 我们开一个数组a,当出现了一个数b时,把该数作为下标调整值,即a[b] = -1,下一次出现该值的时候直接去找这个值作为下标的a值是否为-1即可. #include<stdio.h> #include<string.h> #define MAX 5000010 int p[MAX]={0}; int s[MAX]={0}; int main

UVa 1584 Circular Sequence --- 水题

UVa 1584 题目大意:给定一个含有n个字母的环状字符串,可从任意位置开始按顺时针读取n个字母,输出其中字典序最小的结果 解题思路:先利用模运算实现一个判定给定一个环状的串以及两个首字母位置,比较二者字典序大小的函数, 然后再用一层循环,进行n次比较,保存最小的字典序的串的首字母位置,再利用模运算输出即可 /* UVa 1584 Circular Sequence --- 水题 */ #include <cstdio> #include <cstring> //字符串s为环状,

POJ 3030. Nasty Hacks 模拟水题

Nasty Hacks Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13136   Accepted: 9077 Description You are the CEO of Nasty Hacks Inc., a company that creates small pieces of malicious software which teenagers may use to fool their friends.

poj 3444 Wavelet Compression 模拟水题

水题,直接贴代码. //poj 3444 //sep9 #include <iostream> using namespace std; const int maxN=260; int a[maxN],b[maxN]; int main() { int i,n,m; while(scanf("%d",&n)==1&&n){ for(i=1;i<=n;++i) scanf("%d",&a[i]); m=1; while

【POJ】Cow Multiplication(水题)

Cow Multiplication http://poj.org/problem?id=3673 题意:输入两个数A B,比如123和45   然后算123*45这个运算是指1*4 + 1*5 + 2*4 + 2*5 + 3*4 + 3*5 = 54. 思路:水题. #include<iostream> #include<cmath> #include<cstring> using namespace std; typedef long long ll; const

poj 1004:Financial Management(水题,求平均数)

Financial Management Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 126087   Accepted: 55836 Description Larry graduated this year and finally has a job. He's making a lot of money, but somehow never seems to have enough. Larry has deci