POJ 2081 解题报告

来源:互联网 发布:微信淘宝客发单机器人 编辑:程序博客网 时间:2024/05/21 16:23

这道题是道简单题。我用的set,所以时间巨久。

thestoryofsnow2081Accepted19116K2438MSC++911B

/* ID: thestor1 LANG: C++ TASK: poj2081 */#include <iostream>#include <fstream>#include <cmath>#include <cstdio>#include <cstring>#include <limits>#include <string>#include <vector>#include <list>#include <set>#include <map>#include <queue>#include <stack>#include <algorithm>#include <cassert>using namespace std;const int MAXK = 500000;int main(){std::vector<int> Recaman(MAXK + 1, 0);set<int> existed;for (int m = 1; m <= MAXK; ++m){int am = Recaman[m - 1] - m;bool isexisted = !(existed.find(am) == existed.end());if (am <= 0 || isexisted){am = Recaman[m - 1] + m;}Recaman[m] = am;existed.insert(am);}// for (int m = 0; m <= 14; ++m)// {// printf("%d ", Recaman[m]);// }// printf("\n");int k;while (scanf("%d", &k) && k >= 0){printf("%d\n", Recaman[k]);}return 0;  }


0 0