zoukankan      html  css  js  c++  java
  • ZOJ3449 Doraemon's Number Game III

    数根的扩展版,把一个十进制的数,写成按b进制形式的十进制数,一直下去,直到在[0,10)之间。

    有a(n)*10^n+a(n-1)*10^(n-1)...+a(0) = a(n)*b^n+a(n-1)*b^(n-1)...+a(0) mod (10 - b)
    然后答案就是(n - 10) % (10 - b) + b了。

    代码
    #include <iostream>
    #include
    <math.h>
    #include
    <deque>
    #include
    <string>
    #include
    <vector>
    #include
    <string.h>
    #include
    <stdio.h>
    #include
    <algorithm>
    using namespace std;

    const int MAX = 100005;

    char ch[MAX];
    int len;

    int go(int b)
    {
    if(len == 1 && ch[0] <= '9') return ch[0] - '0';
    int res = 0;
    for(int i = 0; ch[i] != '\0'; i++)
    {
    res
    = res * 10 + ch[i] - '0';
    res
    %= (10 - b);
    }
    res
    = (res - 10) % (10 - b);
    while(res < 0) res += (10 - b);
    return res + b;
    }

    int main()
    {
    while(gets(ch))
    {
    len
    = strlen(ch);
    for(int i = 1; i <= 9; i++)
    {
    if(i == 1) printf("%d", go(i));
    else printf(" %d", go(i));
    }
    printf(
    "\n");
    }
    }
  • 相关阅读:
    POJ_1485_dp
    POJ_1376_bfs
    [noi1994]海盗
    [noi1755]Trie
    [luogu3733]八纵八横
    [noi1774]array
    [noi1773]function
    [noi1754]SA
    [noi1779]D
    [bzoj4873]寿司餐厅
  • 原文地址:https://www.cnblogs.com/litstrong/p/1923301.html
Copyright © 2011-2022 走看看