题目

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. 洛谷 - P2278 - 操作系统 - 模拟

    https://www.luogu.org/problemnew/show/P2278 题目没有说同时到达的优先级最大的应该处理谁. 讲道理就是处理优先级最大的. #include<bits/s ...

  2. kuangbin带你飞 - 合集

    [题目列表] 之前有一些做过了的,这次从数论开始?

  3. MongoDb 安装服务 以及 安全配置

    安装MongoDb 的服务 命令如下: (cmd以管理员运行) mongod –logpath "D:\Program Files\mongodb\data\logs.txt" – ...

  4. [Xcode 实际操作]八、网络与多线程-(4)使用UIApplication对象发送短信

    目录:[Swift]Xcode实际操作 本文将演示如何使用应用程序单例对象,发送短信的功能. 在项目导航区,打开视图控制器的代码文件[ViewController.swift] 注:需要使用真机进行测 ...

  5. IT兄弟连 JavaWeb教程 EL与JSTL表达式经典面试题

    1.简述EL表达式的作用 EL表达式的作用可分为以下三类 访问Bean的属性. 输出简单的运算结果. 获取请求参数值. 2.JSP标签的作用?如何定义? JSP标签可以分离JSP页面的内容和逻辑,业务 ...

  6. MyBatist庖丁解牛(三)

    从MyBatis代码实现的角度来看,MyBatis的主要的核心部件有以下几个: SqlSession:作为MyBatis工作的主要顶层API,表示和数据库交互的会话,完成必要数据库增删改查功能: Ex ...

  7. time库的使用

    首先只需要 import time (典型的,标准的python库的使用方法) 主要包括三类函数 ——时间获取:time() , ctime() , gmtime() ——时间格式化: strftim ...

  8. android BottomNavigationView 底部显示3个以上的item

    你现在可以用app:labelVisibilityMode="[labeled, unlabeled, selected, auto] labeled 所有的标签都是可见的. unlabel ...

  9. Java | 基础归纳 | Map.Entry<String, String>

    public class Test { private static Map<String,String> student; private static void init() { st ...

  10. Jmeter-提取Json数据进行关联

      1:Json后置处理器提取结果作为下一个sampler的传入参数 1.1:[线程组]->[简单控制器]->[HTTP sampler]->[Beanshell后置取样器]-> ...