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");
    }
    }
  • 相关阅读:
    Ubuntu下ClickHouse安装
    redis.conf配置详解(转)
    php使用sftp上传文件
    ubuntu下安装nginx1.11.10
    cookie和session的区别
    linux下Redis主从复制
    linux-ubuntu 安装配置Redis
    php的常量
    Ubuntu防火墙配置
    技术资料
  • 原文地址:https://www.cnblogs.com/litstrong/p/1923301.html
Copyright © 2011-2022 走看看