UVA 12050 - Palindrome Numbers 模拟

题目大意:给出i,输出第i个镜像数,不能有前导0.

题解:从外层开始模拟

#include <stdio.h>
int p(int x)
{
    int sum, i;
    for(sum=i=1;i<=x;i++)
        sum *= 10;
    return sum;
}
int main()
{
    int n, i, j, t, cs[1000], c;
    while(~scanf("%d", &n))
    {
        if(n==0)
            break;
        i=1;
        while(n>9*p((i-1)/2))
        {
            n -= 9*p((i-1)/2);
            i++;
        }
        c = (i+1)/2;
        t=1;
        while(c)
        {
        c--;
        cs[t]=0;
        while(n>p(c))
        {
            n -= p(c);
            cs[t]++;
        }
        t++;
        }
        cs[1]++;
        for(j=1;j<t;j++)
            printf("%d", cs[j]);
        if(i%2==0)
            printf("%d", cs[t-1]);
        for(j=t-2;j>=1;j--)
            printf("%d", cs[j]);
            printf("\n");
    }
    return 0;
}
时间: 2024-11-02 14:10:32

UVA 12050 - Palindrome Numbers 模拟的相关文章

Uva - 12050 Palindrome Numbers【数论】

题目链接:uva 12050 - Palindrome Numbers 题意:求第n个回文串 思路:首先可以知道的是长度为k的回文串个数有9*10^(k-1),那么依次计算,得出n是长度为多少的串,然后就得到是长度为多少的第几个的回文串了,有个细节注意的是, n计算完后要-1! 下面给出AC代码: 1 #include <bits/stdc++.h> 2 typedef long long ll; 3 using namespace std; 4 const int maxn=3010; 5

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). Additionallynumbers can of course be ordered in size. The ?rst few

UVA - 12046 Great Numbers

Description Problem G - Great Numbers In this problem you have to count the number of great numbers of length n. Here a great number must have the following property: the number must be divisible by all of its decimal digits. it does not contain any

UVA - 471 Magic Numbers

Description  Magic Numbers  Write a program that finds and displays all pairs ofintegers and such that: neither nor have any digits repeated; and , where N is a given integer; Input and Output The input file consist a integer at the beginning indicat

UVa - 12050

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). Additionallynumbers can of course be ordered in size. The first fe

zoj2000 Palindrome Numbers

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

Uva - 1513 Moive collection ( 模拟栈 + 树状数组基本操作 )

Uva - 1513 Moive collection ( 模拟栈 + 树状数组基本操作 ) 题意: 一个书架,原来所有的书都是按顺序摆好的,书的编号从1开始到n 操作: 取出一本书,统计在这本书之前有多少本书,统计完之后,将这本书放在书架的第一位. 如:  1 2 3 4 5取4   4 1 2 3 5 (取之前,有3本书在4前面,取完后,将4放在栈顶)取4   4 1 2 3 5 (取之前,有0本书在4前面,取完后,将4放在栈顶)取2   2 4 1 3 5 (取之前,有2本书在2前面,取完

uva 1156 - Pixel Shuffle(模拟+置换)

题目链接:uva 1156 - Pixel Shuffle 题目大意:给定一个N*N的黑白位图,有7种操作,并且对应在指令后加上'-'即为操作的逆,给定N和一系列操作,(从最后一个开始执行),问说这一套指令需要执行多少次才能形成循环. 解题思路:模拟指令执行后获得一个置换,分解成若干的循环,各个循环长度的最小公倍数即使答案. #include <cstdio> #include <cstring> #include <algorithm> using namespace

Palindrome Numbers(LA2889)第n个回文数是?

 J - Palindrome Numbers Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Practice UVALive 2889 WA了一版面,我也是醉了,就因为一个编译环境不同...... 说多了都是泪. 题目链接:请点击UVALive 2889 转载请注明出处:寻找&星空の孩子 #include<stdio.h> #define LL lo