POJ2402/UVA 12050 Palindrome Numbers 数学思维
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 ∗ 109
).
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,输出第i个回文数,不能有前导0.
题解:第一和最后一位不为0,
我们预处理i位数有多少,以及 在不是第一位和最后一位情况下i位有多少情况
再不断细分就好了
//meek///#include<bits/stdc++.h>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include<iostream>
#include<bitset>
#include<vector>
#include <queue>
#include <map>
#include <set>
#include <stack>
using namespace std ;
#define mem(a) memset(a,0,sizeof(a))
#define pb push_back
#define fi first
#define se second
#define MP make_pair
typedef long long ll; const int N = ;
const int M = ;
const int inf = 0x3f3f3f3f;
const int MOD = ;
const double eps = 0.000001; ll a[N],sum[N],b[N],s;
void init() {s=;
a[] = ;b[] = ;
a[] = ;b[] = ;
for(int i=;i<=;i++) {
a[i] = a[i-] * ;
}s=;
for(int i=;i<=;i++) {
b[i] = *a[i-];
s+=b[i];
// cout<<s<<endl;
}
}
int main() {
init();
ll n, num, ans[N];
while(scanf("%lld",&n)!=EOF) {
if(!n) break;
mem(ans);
int l,r,mm;
for(int i=;i<=;i++) {
if(b[i]>=n) {
num = i;
mm = num;
l = , r = num;
while(l<=r) {
if(num == ) {
if(l!=) n--;
ans[l] = n;
ans[r] = n;break;
}
if(num == ) {
if(l!=)n--;
ans[l] = n;
ans[r] = n;break;
}
ans[l] = n/a[num-] + (l == ?:);
n = n%a[num-];
if(n == && num-!=) {
ans[l]--;
n = a[num-];
}
ans[r] = ans[l];
l++,r--;num-=;
}
break;
}
n -= b[i];
}
for(int i=;i<=mm;i++) printf("%lld",ans[i]);
printf("\n");
}
return ;
}
代码
POJ2402/UVA 12050 Palindrome Numbers 数学思维的更多相关文章
- Uva - 12050 Palindrome Numbers【数论】
题目链接:uva 12050 - Palindrome Numbers 题意:求第n个回文串 思路:首先可以知道的是长度为k的回文串个数有9*10^(k-1),那么依次计算,得出n是长度为多少的串,然 ...
- UVa 12050 - Palindrome Numbers (回文数)
A palindrome is a word, number, or phrase that reads the same forwards as backwards. For example, th ...
- UVA 12050 - Palindrome Numbers 模拟
题目大意:给出i,输出第i个镜像数,不能有前导0. 题解:从外层开始模拟 #include <stdio.h> int p(int x) { int sum, i; ;i<=x;i+ ...
- UVa - 12050 Palindrome Numbers (二分)
Solve the equation: p ∗ e −x + q ∗ sin(x) + r ∗ cos(x) + s ∗ tan(x) + t ∗ x 2 + u = 0 where 0 ≤ x ≤ ...
- HDU 6659 Acesrc and Good Numbers (数学 思维)
2019 杭电多校 8 1003 题目链接:HDU 6659 比赛链接:2019 Multi-University Training Contest 8 Problem Description Ace ...
- UVA 11461 - Square Numbers 数学水题
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- POJ 3252 Round Numbers 数学题解
Description The cows, as you know, have no fingers or thumbs and thus are unable to play Scissors, P ...
- UVa 10006 - Carmichael Numbers
UVa 10006 - Carmichael Numbers An important topic nowadays in computer science is cryptography. Some ...
- HDU 5062 Beautiful Palindrome Number(数学)
主题链接:http://acm.hdu.edu.cn/showproblem.php? pid=5062 Problem Description A positive integer x can re ...
随机推荐
- hdu 3836 Equivalent Sets
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=3836 Equivalent Sets Description To prove two sets A ...
- python生成带参数二维码
#coding:utf8 import urllib2 import urllib import json import string import random class WebChat(obje ...
- Effective Objective-C 2.0之Note.02
1.多用类型常量,少用#define预处理指令 不要用预处理指令定义常量.这样定义出来的常量不含类型信息,编译器只是会在编译前据此执行查找与替换操作.即使有人重新定义了常量值,编译器也不会产生警告信息 ...
- 条款38:通过聚合设计has-a或者is-implemented-in-terms-of
聚合:类型之间的一种关系,就是一种类型内含有另一种类型的变量. has-a: class Address { }; class PhoneNumber { }; class Person { publ ...
- java数据结构和算法------堆排序
package iYou.neugle.sort; public class Heap_sort { public static void HeapSort(double[] array) { for ...
- 代码实现Autolayout
代码实现Autolayout的步骤 利用NSLayoutConstraint类创建具体的约束对象 添加约束对象到相应的view上 - (void)addConstraint:(NSLayoutCons ...
- 四则运算2+psp0级表格
四则运算2 一.题目和要求 题目:写一个能自动生成小学四则运算题目的程序,要求一次输出不少于30道,只能是整数100以内的四则运算(四则运算1升级版) 要求: 1.题目避免重复 2.可定制(数量/打印 ...
- ORM 框架
1.Dapper 2.Entity Framework(EF) http://www.cnblogs.com/n-pei/archive/2011/09/06/2168433.html
- Java Synchronized Blocks vs. Methods
It's possible to synchronize both an entire method and a section of code within a method, and you ma ...
- Codeforces Round #353 (Div. 2) E. Trains and Statistic 线段树+dp
题目链接: http://www.codeforces.com/contest/675/problem/E 题意: 对于第i个站,它与i+1到a[i]的站有路相连,先在求所有站点i到站点j的最短距离之 ...