zoj2000 Palindrome Numbers

zoj2744 Palindromes 字符串的题 题意是求给一个字符串算出其中有多少个回文子串(每个回文子串必须是连续的),关于这题由于数据范围才5000,所以可以用O(N*N)的动态规划去做或者是用暴力的搜索,每次枚举回文串的对称中点复杂度不超过O(N*N),但是用dp做就很蛋疼了,因为内存限制存不了所有的状态,所以得用滚动数组去存,下面将给出几种不同实现的代码。如果暴力枚举中点方法确实很简单,但我还是建议,写一下dp,/可以锻炼一下代码能了, 阅读详情

Palindrome Numbers

Time Limit: 2 Seconds      Memory Limit: 65536 KB

A palindrome is a word, number, or phrase that reads the same forwards as backwards. For example, the name "anna" is a palindrome. Numbers can also be palindromes (e.g. 151 or 753357). Additionally numbers can of course be ordered in size. The first few palindrome
numbers are: 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, ...

The number 10 is not a palindrome (even though you could write it as 010) but a zero as leading digit is not allowed.


Input

The input consists of a series of lines with each line containing one integer value i (1<= i <= 2*10^9 ). This integer value i indicates the index of the palindrome number that is to be written to the output, where index 1 stands for the first palindrome number (1), index 2 stands for the second palindrome number (2) and so on. The input is terminated by a line containing 0.


Output

For each line of input (except the last one) exactly one line of output containing a single (decimal) integer value is to be produced. For each input value i the i-th palindrome number is to be written to the output.


Sample Input

1
12
24
0


Sample Output

1
33
151



题意:求第i个回文数字;

解析:

位数为1的回文个数:9

位数为2的回文个数:9

位数为3的回文个数:90

位数为4的回文个数:90

位数为5的回文个数:900

位数为6的回文个数:900

位数为7的回文个数:9000

位数为8的回文个数:90000

.……

位数为n的回文个数:9*(10^((n-1)/2)),

将这些回文数拆分一半,可以发现

---------------------------------------------------------1位

1 2 3 4 5 6 7 8 9

---------------------------------------------------------2位

1 2 3 4 5 6 7 8 9

---------------------------------------------------------3位

10 11 12 13 14 15 16 17 18 19

20 21 22 23 24 25 26 27 28 29

……

90 91 92 93 94 95 96 97 98 99

----------------------------------------------------------4位

10 11 12 13 14 15 16 17 18 19

20 21 22 23 24 25 26 27 28 29

……

90 91 92 93 94 95 96 97 98 99

---------------------------------------------------------5位

100 101 102 103 104 105 106 107 108 109

110 111 112 113 114 115 116 117 118 119

……

990 991 992 993 994 995 996 997 998 999

---------------------------------------------------------6位

……

参考代码:

#include <iostream>
using namespace std;
typedef long long ll;
ll pow(int a,int b){
	ll ans = 1;
	for (int i=0;i<b;i++){
		ans*=a;
	}
	return ans;
}
int main(){
	ll n;
	while (cin>>n&&n){
		int count=1;
		int q=9;
		while (n>q){
			n-=q;
			count++;
			if (n>q){
				n-=q;
				count++;
			}
			else
				break;
			q*=10;
		}
		//cout<<"n="<<n<<endl;
		int k=(count-1)/2;
		//cout<<"k="<<k<<endl;
		ll ans=pow(10,k)+n-1;
		//cout<<"ans="<<ans<<endl;
		//cout<<"count="<<count<<endl;
		int a[20],s=0;
		cout<<ans;
		while (ans){
			a[s++]=ans%10;
			ans/=10;
		}
		for (int j=count/2-1;j>=0;j--){
			if (j<0)
				break;
			cout<<a[s-1-j];
		}
		cout<<endl;
	}
	return 0;
}


参考代码:


Unity动画状态机实战:Trigger和Bool参数到底怎么选?附5个常见场景解析 本文深入解析Unity动画状态机中Trigger和Bool参数的核心差异与应用场景。通过对比两者在描述瞬时事件与持续状态上的本质区别,并结合角色移动、攻击连招、跳跃落地、受击死亡及环境交互等5个实战场景,提供了清晰的选择逻辑与避坑指南,帮助开发者构建更健壮、易维护的动画逻辑。 阅读详情

相关推荐

论文阅读4——一种宽频带圆极化微带天线的设计

论文阅读——一种宽频带圆极化微带天线的设计(现在才觉得开始弄懂了一点,懂了一点之后又更糊涂了……)

weixin_64612422的博客 2316

Palindrome Number 回文数

判断一个整数是否是回文数。回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数。 示例 1: 输入: 121 输出: true 示例 2: 输入: -121 输出: false 解释: 从左向右读, 为 -121 。 从右向左读, 为 121- 。因此它不是一个回文数。 示例 3: 输入: 10 输出: false 解释: 从右向左读, 为 01 。因此它不是一个回文...

qq_26410101的博客 306

神领物流-day01-项目概述

公司从2019年开始业务快速扩张,网点数量从138家扩展至540家,车辆从170台增长到800台。同时,原有的系统非常简单,比如车辆的调度靠人工操作、所有的货物分拣依靠人员,核心订单数据手动录入,人效非常低。随着业务不断演进,技术的不断提升,原有运输管理系统已无法满足现有快速扩展下的业务需求,但针对现有系统评估后发现,系统升级成本远高于重新研发。因此,公司决定基于现有业务体系进行重新构建,打造一套新的TMS运输系统,直接更替原有系统。

心飞为你飞 2255

Palindrome Number(判断数字是不是回文数)-python

Determine whether an integer is a palindrome. Do this without extra space.解答 : 有的答案是把数转成字符串,逆序之后与原来的相等,那么就是回文数;本人提供的答案是,设置两个指针,分别指向头部和尾部,对比对应的数是否相等,直到指针指向中间位置,结束。class Solution(object):    def isPalin...

qq_22179091的博客 594

从零开始:如何用PSINS工具箱构建你的第一个IMU误差模型

本文详细介绍了如何使用严恭敏教授开发的PSINS工具箱构建IMU误差模型,涵盖从基础参数设置到高级误差建模的全过程。通过imuerrset函数配置陀螺零偏、随机游走等核心参数,并结合实战案例展示消费级MEMS器件的误差建模方法,帮助用户提升惯性导航系统的精度与可靠性。

weixin_29284885的博客 322

Raptor码(一):2007RFC5053标准编解码学习

RFC 5053 标准

a_beatiful_knife的博客 3493

ZOJ 1078 :Palindrom Numbers

简单题,直接贴代码: #include int main() { int n; int i,j; while(scanf("%d",&n)&&n) { int sign=0; char c[30]; int base[17]={0}; for(i=2;i<=16;i++) { int m=n; int len=0; while(m) {

754

立创星火计划:基于STM32H743VIH6的Maverick_H743_MK1.0高性能开源飞控硬件全解析

本文详细解析了基于STM32H743VIH6核心的Maverick_H743_MK1.0高性能开源飞控硬件设计。重点阐述了采用双IMU冗余设计、高精度气压计、多路独立电源管理以及丰富接口(如CAN总线)的考量,旨在为穿越机、科研无人机等平台提供强大、可靠的飞行控制解决方案。

weixin_28787801的博客 197

9.回文数(Palindrome Number)

题目描述判断一个整数是否是回文数。不能使用辅助空间(即要求空间复杂度为O(1))。负整数可以是回文数吗?(例如 -1,不可以,所有的负数都不是回文数)如果你打算把整数转为字符串,请注意不允许使用辅助空间的限制。你也可以考虑将数字颠倒。但是如果你已经解决了 “颠倒整数” 问题的话,就会注意到颠倒整数时可能会发生溢出。你怎么来解决这个问题呢?解题思路分析和实现方法方法一:      第一反应就是将整数...

写后端的小学生 2938

VTK实战完整教程介绍

该专栏以VTK提供的Example为基础,讲解VTK中的相关接口和使用方法。订阅该专栏,带你了解所有VTK的功能,以便VTK更好的解决工作中遇到的问题。一起学习起来吧!

qq_40041064的博客 2503

cartographer ceres后端优化

这里引用一篇文章作用一:用户可以选择使用Problem::AddParameterBlock显式添加参数块;在显式添加的时候ceres会内部进行额外的正确性检查。当Problem::AddParameterBlock()不存在时,Problem::AddResidualBlock()会隐式添加参数块,因此不需要显式调用Problem::AddParameterBlock()函数。ps:类似构造函数,显式构造函数。

南北粉面馆 802

ZOJ 2000 Palindrome Numbers

<br />求回文数,不过数据量有点大,不能一个一个检测,需要找出回文数的规律,然后根据规律推,,<br /> <br />#include<stdio.h> #include<string.h> #include<stdlib.h> int ten(int n) { int i,sum = 1; for( i = 1; i <= n; i++ ) sum *= 10; return sum; } int main(void) { in

闷瓜蛋子的专栏 971

导航系统 | 全球四大卫星导航系统(2025)核心能力对比分析

北斗系统通过GEO卫星(80°E、110.5°E、140°E)实现区域增强,其IGSO卫星在亚太地区形成"8"字形轨迹,使该区域可见卫星数量比GPS多4-6颗,显著提升复杂环境下的定位可用性[13]。北斗短报文功能在2025年云南地震救援中发挥关键作用,被困人员通过北斗终端发送120字求救信息,实现"位置+状态"一体化上报,救援响应时间缩短40%[15]。北斗通过三频信号(B1C/B2a/B3)消除电离层延迟误差,在城市峡谷环境下定位连续性达99.98%,优于GPS的99.95%[5]。

尘世冰封的专栏 2611

LeetCode - 解题笔记 - 9 - Palindrome Number

预览Palindrome NumberSolution 1Solution 2 Palindrome Number Solution 1 既然题目中要求尽量不要把整数转换成字符串进行回文判断,那么所有直接查看各位数字的方法尽量都不要使用(思路都是一样的)。从回文数最根本的定义上来看:前一半和后一半的逆序是相同的,那么可以通过把数字逆序进行判断。在C++等语言中,直接逆序任意整数可能会溢出,因此需要只逆序后一半。由于我们尽量不要按照各个数位去检查,因此比较灵活的地方就是要考虑如何判断“过半” 根据上面的分析,

支锦铭的博客 276

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

POJ 2402 Palindrome Numbers

Palindrome Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3568   Accepted: 1333 Description A palindrome is a word, number, or phrase that reads the s

你说我能坚持多久。。 604

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

ZOJ-1078-Palindrom Numbers

Statement of the Problem We say that a number is a palindrom if it is the sane when read from left to right or from right to left. For example, the number 75457 is a palindrom. Of course, the proper

宇哥的博客 522

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

UVALive2889 Palindrome Numbers(回文数,神级代码....)

题目链接(Virtual Judge):http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=33603 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=890

AC_Dreameng 1278

Palindrome Numbers(UVALive 2889)

长度为2*i+1和2*(i+1)的数的个数都为9*10^i,由此可知N的长度和N为该长度的第几个数。

TryMyEdge 508

Palindrome Number

1.前言 最近在学习Python教程,学习到关于回文数(palindrome number)的算法, 于是想写一篇关于回文数的博客,放在Math专栏,当做一个知识点,也是作为积累的一步吧。 2.回文数 什么是回文数? A palindromic number or numeral palindrome is a number that remains the same when its d...

czq_g的博客 445

ZOJ--1078:Palindrom Numbers

思路: 这个题呢 首先知道怎么转换进制 , 就是一直取余。 然后判断这个数是否为回文数即可 比较简单不做过多解释 java: import java.util.Scanner; public class Palindrom_Numbers_1078 { static int arr[]=new int[1000]; static int b[]=new int[15]; publi

yf224的博客 607

E - Palindrome Numbers POJ - 2402

A palindrome is a word, number, or phrase that reads the same forwards as backwards. For example, the name “anna” is a palindrome. Numbers can also be palindromes (e.g. 151 or 753357). Additionally num

Irish_Moonshine的博客 429

9. Palindrome Number【回文数字】

描述 Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward. 判断一个整数是否是回文数。回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数 例子 思路 方法1: 把数字变为字符串,然后比较–效率最低 ...

puspos的博客 514

Palindrome Numbers【模拟】

Palindrome Numbers Time Limit:1000MS Memory Limit:65536K Total Submissions:3948 Accepted:1505 Descr...

苏格拉没有底 298

Chang'an(Palindrome Numbers-回文数字统计)

统计前半个回文串 #include using namespace std; #define For(i,n) for(int i=1;i<=n;i++) #define ForD(i,n) for(int i=n;i;i--) #define ForkD(i,k,n) for(int i=n;i>=k;i--) #define Rep(i,n) for(int i=0;i<

nike0good |Oier&ACMer | 熟能生巧 1096

UVA 12050 Palindrome Numbers (规律题)*

题目链接:https://cn.vjudge.net/problem/UVA-12050 #include&lt;bits/stdc++.h&gt; using namespace std; #define debug puts("YES"); #define rep(x,y,z) for(int (x)=(y);(x)&lt;(z);(x)++) #define read(x,y) sca...

满月照亮的路 300

C++ - Palindrome Numbers

Palindrome Numbers A palindromic number is a number (such as 626) that remains the same when its digits are reversed. Write a function that returns true if a given number is a palindrome, and false, if it is not. Complete the given function, so that the co

m0_52377535的博客 437
上一篇: zoj 1577 GCD & LCM
下一篇: UVA100 The 3n + 1 problem
JinbaoSite0144
博客等级 码龄12年 231粉丝 157原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值