题目

HihoCoder - 1878

题目大意

给出k,让求出第k个回文数(k的“长度”不超过1e5)

题解

之前做过类似的题,是统计各阶段的数找到第K个回文数,但这里K太大,需要寻找新的方法。

打表找规律:

只有一位数:减一输出

否则:

若第0位为2~9 :首位减一,0~len-2反转贴后面

若第0位为1:若第1位为1~9:丢掉首位,剩下的反转贴后面

若第1位为0:丢掉首位,第1位改成9,2~len-2反转贴后面.

AC代码

#include<cstdio>
#include<iostream>
#include<string>
#include<sstream>
using namespace std; void solve(string str)
{
int len = str.length(); if (len == )
{
printf("%c\n", str[] - );
return;
} if (str[] == '')
{
if (str[] == '')
{
str[] = '';
for (int i = ; i < len; i++) printf("%c", str[i]);
for (int i = len - ; i >= ; i--) printf("%c", str[i]);
printf("\n");
}
else
{
for (int i = ; i < len; i++) printf("%c", str[i]);
for (int i = len - ; i >= ; i--) printf("%c", str[i]);
printf("\n");
}
}
else
{
str[] = str[] - ;
for (int i = ; i < len; i++) printf("%c", str[i]);
for (int i = len - ; i >= ; i--) printf("%c", str[i]);
printf("\n");
}
} int main()
{
int T;
scanf("%d", &T);
while (T--)
{
string str;
cin >> str;
solve(str);
}
}

打表程序

#include<cstdio>
#include<iostream>
#include<sstream>
#include<string>
using namespace std; typedef long long LL; const LL maxn = 1e18; void ToString(LL num, string& str)
{
stringstream ss;
ss << num;
ss >> str;
} bool ispd(string str)
{
bool flag = true;
int len = str.length();
for (int i = ; i < len / ; i++)
if (str[i] != str[len - - i]) flag = false;
return flag;
} int main()
{
LL cnt = ;
for (LL i = ; i < maxn; i++)
{
string s;
ToString(i, s);
if (ispd(s)) cout << cnt++ << ' ' << i << endl;
}
return ;
}

参考链接:https://blog.csdn.net/hxxjxw/article/details/84205963

2018 北京区域赛 I - Palindromes (找规律)的更多相关文章

  1. Heshen's Account Book HihoCoder - 1871 2018北京区域赛B题(字符串处理)

    Heshen was an official of the Qing dynasty. He made a fortune which could be comparable to a whole c ...

  2. ICPC 2018 焦作区域赛

    // 2019.10.7 练习赛 // 赛题来源:2018 ICPC 焦作区域赛 // CF链接:http://codeforces.com/gym/102028 A Xu Xiake in Hena ...

  3. 2018 ACM-ICPC 区域赛(青岛站)题解整理

    题目链接 C - Flippy Sequence(组合数学+分类讨论) 两区间异或一下,分段考虑,如果全为0则任选两相同区间,答案为$C_{n+1}^{2}=\frac{n(n+1)}{2}$,只有一 ...

  4. 2018南京区域赛G题 Pyramid——找规律&&递推

    先手动推出前10项,再上BM板子求出递推式 $A_n = 5A_{n-1} - 10A_{n-2} + 10A_{n-3} - 5A_{n-4} + A_{n-5}$,根据特征根理论可求出特征方程 $ ...

  5. hihoCoder #1871 : Heshen's Account Book-字符串暴力模拟 自闭(getline()函数) (ACM-ICPC Asia Beijing Regional Contest 2018 Reproduction B) 2018 ICPC 北京区域赛现场赛B

    P2 : Heshen's Account Book Time Limit:1000ms Case Time Limit:1000ms Memory Limit:512MB Description H ...

  6. hihoCoder #1870 : Jin Yong’s Wukong Ranking List-闭包传递(递归) (ACM-ICPC Asia Beijing Regional Contest 2018 Reproduction A) 2018 ICPC 北京区域赛现场赛A

    P1 : Jin Yong’s Wukong Ranking List Time Limit:1000ms Case Time Limit:1000ms Memory Limit:512MB Desc ...

  7. 2017 ACM-ICPC 北京区域赛记录

    ------------------------------------------------------------------------------ 出发日 拖着一个大箱子走是真的累. 下午三 ...

  8. HDU 5122 K.Bro Sorting(2014北京区域赛现场赛K题 模拟)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5122 解题报告:定义一种排序算法,每一轮可以随机找一个数,把这个数与后面的比这个数小的交换,一直往后判 ...

  9. HDU 5119 Happy Matt Friends(2014北京区域赛现场赛H题 裸背包DP)

    虽然是一道还是算简单的DP,甚至不用滚动数组也能AC,数据量不算很大. 对于N个数,每个数只存在两个状态,取 和 不取. 容易得出状态转移方程: dp[i][j] = dp[i - 1][j ^ a[ ...

随机推荐

  1. codeforces 813C The Tag Game 树+dfs追击问题

    C. The Tag Gametime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutpu ...

  2. .NET 5 - 下一代.NET

    不知不觉中微软已经计划推出了下一代的.NET了,我们先来看一下新的.NET有包含什么 What's new in .NET 5? .NET 5将会引入新的APIs,运行时功能和新的语言特色. 在运行时 ...

  3. iOS 中 延迟操作四种方式

    本文列举了四种延时执行某函数的方法及其一些区别.假如延时1秒时间执行下面的方法. - (void)delayMethod { NSLog(@"execute"); } 1.perf ...

  4. builtin_shaders-5.3.4f1学习-Unlit/Texture

    // Unlit shader. Simplest possible textured shader. // - no lighting // - no lightmap support // - n ...

  5. 蓝桥杯T42(八数码问题)

    题目链接:http://lx.lanqiao.cn/problem.page?gpid=T42 题意:中文题诶- 思路:bfs 将没种九宫格的状态看作一个状态节点,那么只需求起始节点到目标节点的最短路 ...

  6. Node.js 的回调模式

    我们都知道在javaScript中,如果在head标签里面引入script脚本,在打开web的时候,浏览器会先加载head中的信息,再加载body的信息: 如果head中有link标签,浏览器会开启一 ...

  7. 学习Mahout(三)

    开发+运行第一个Mahout的程序 代码: /** * Licensed to the Apache Software Foundation (ASF) under one or more * con ...

  8. bzoj2502清理雪道

    传送门 好题啊,由于每个点既可以进,也可以出,就可以新建一个源点和汇点,对于每个点都连边,然后就是最小流板子了. 代码: #include<cstdio> #include<iost ...

  9. linux常用命令(ubuntu)

    编辑: vi [path] vim [path] :q 退出 :wq 保存退出 查看进程 ps ps -aux | grep mem 查看全部含 “mem”的进程 ps –aux  查看全部 在系统启 ...

  10. python学习之环境搭建 输入输出

    一 环境搭建: 在安装好python2.7之后就可以利用其命令行和交互式模式进行基本的输入和输出测试了,但这样编码无法保存,所以就需要用到好用的编辑器和环境搭建了,这里用uestdio. 1.1打开u ...