Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

其实先枚举出前N个回文数,你就会发现规律(附详解)

Posted by Eov_Second at 2016-11-25 23:33:24 on Problem 2402
N-----------------第N个回文数
   1---------------1
  10---------------11
  19---------------101
 109---------------1001
 199---------------10001
1099---------------100001
1999---------------1000001

左边和右边的规律很明显,并且还可以看到,从101到1001增大了900,回文数增加了90个,10001到100001增大了90000,回文数增加了900个。找到规律后不难得到思路如下:
1.对于给定输入N,找到N在左边的位置。例如N为1530,则N位于1099-1999之间。
2.第1099个回文数是100001,100001每增加100000,回文数增加100个,所以(1530-1099)/100 = 4, 也就是第1499个回文数是500005(在100001基础上增加400000)
3.500005基础上每增加10000,回文数增加10个,所以(1530 - 1499)/10 = 3,所以得到第1529个回文数是530035
4.530035基础上每增加1000,回文数增加1个,所以第1530 - 1529 = 1,得到第1530个回文数是531135

聪明的你马上就看出来了上面的2-3-4步放到一个循环里就可以了

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator