2018 北京区域赛 I - Palindromes (找规律)
题目
题目大意
给出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 (找规律)的更多相关文章
- 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 ...
- ICPC 2018 焦作区域赛
// 2019.10.7 练习赛 // 赛题来源:2018 ICPC 焦作区域赛 // CF链接:http://codeforces.com/gym/102028 A Xu Xiake in Hena ...
- 2018 ACM-ICPC 区域赛(青岛站)题解整理
题目链接 C - Flippy Sequence(组合数学+分类讨论) 两区间异或一下,分段考虑,如果全为0则任选两相同区间,答案为$C_{n+1}^{2}=\frac{n(n+1)}{2}$,只有一 ...
- 2018南京区域赛G题 Pyramid——找规律&&递推
先手动推出前10项,再上BM板子求出递推式 $A_n = 5A_{n-1} - 10A_{n-2} + 10A_{n-3} - 5A_{n-4} + A_{n-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 ...
- 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 ...
- 2017 ACM-ICPC 北京区域赛记录
------------------------------------------------------------------------------ 出发日 拖着一个大箱子走是真的累. 下午三 ...
- HDU 5122 K.Bro Sorting(2014北京区域赛现场赛K题 模拟)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5122 解题报告:定义一种排序算法,每一轮可以随机找一个数,把这个数与后面的比这个数小的交换,一直往后判 ...
- HDU 5119 Happy Matt Friends(2014北京区域赛现场赛H题 裸背包DP)
虽然是一道还是算简单的DP,甚至不用滚动数组也能AC,数据量不算很大. 对于N个数,每个数只存在两个状态,取 和 不取. 容易得出状态转移方程: dp[i][j] = dp[i - 1][j ^ a[ ...
随机推荐
- Flutter实战视频-移动电商-30.列表页_商品列表UI界面布局
30.列表页_商品列表UI界面布局 小程序里面的布局方式 小程序的图片上这里使用的是warp布局,因为首页里面火爆专区,已经用过了warp来布局了. 所以这里我们没有必要再讲一遍,这里我们使用List ...
- 3-2带命令行参数的Java
命令行参数: 主方法Main 小括号里面的内容就是命令参数: String[] args class ArgsDemo{ public static void main(String[] args){ ...
- C#操作句柄
1.直接上例子吧:收集系统信息msinfo32时,会有一个弹窗,现在要隐藏该弹窗,首先看没有通过句柄隐藏弹窗的现象 2.收集系统信息导入到一个位置 代码: Process[] msinfo32proc ...
- SQL Server服务器连接配置
一.首先确保服务器能在本地打开数据库 如果碰到本地无法连接到数据库,首先要确认上图中两个服务是否开启 二.其次,要配置远端可连接的用户 如图,配置数据库[属性]中[安全性]为混合验证,勾中允许远程连接 ...
- Cannot set headers after they are sent to the client
D:\le\node_modules\mysql\lib\protocol\Parser.js: throw err; // Rethrow non-MySQL errors ^ Error [ERR ...
- spring boot 使用Schedule创建轻量级定时任务
Scheduled SpringBoot配置定时任务可以直接使用自带的Scheduled,这相当于一个轻量级的Quartz,它可以让我们直接使用注解来完成定时任务的配置. Scheduled调度时间设 ...
- spark sql 优化心得
本篇文章主要记录最近在使用spark sql 时遇到的问题已经使用心得. 1 spark 2.0.1 中,启动thriftserver 或者是spark-sql时,如果希望spark-sql run ...
- assembly x86(nasm)画三角形等图形的实现(升级版)
https://www.cnblogs.com/lanclot-/p/10962702.html接上一篇 本来就有放弃的想法,可是有不愿退而求次, 然后大神室友写了一个集海伦公式计算三角形面积, 三点 ...
- 48个国际音标-/iː/
/iː/ 是单元音前元音,是个长元音. ***ee,ea,ie,ei*** 1)张开你的嘴巴,好像你在微笑,露出你的牙齿,嘴唇向两边伸开,成扁平形. 2)将舌前部向硬腭尽量抬起.舌头轻微接触下齿背部. ...
- nacos启动
nacos下载 https://github.com/alibaba/nacos 1.执行数据库脚本 2.修改配置文件application.propertiesspring.datasource.p ...