zoukankan      html  css  js  c++  java
  • Codeforces Round #347 (Div. 2) C. International Olympiad 找规律

    题目链接:

    http://codeforces.com/contest/664/problem/C

    题解:

    这题最关键的规律在于一位的有1989-1998(9-8),两位的有1999-2098(99-98),三位的有2099-3098(099-098),四位的有3099-13098(3099-3098)

    所以关键字长度一样的会连续出现,1989+0代表一位的开始,1989+10代表两位的开始,1989+10+100代表三位的开始,

    现在给你一个长度为len的标志,就可以找出该数位的起始位置1989+10+100+...+10^(len-1),终止位置为1989+10+100+...+10^len-1,这个数位里面前len位固定的数是唯一的,完全可以马上找到。

    代码:

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    using namespace std;
    
    char str[22];
    
    int ten[22];
    void pre() {
        ten[0] = 1;
        for (int i = 1; i < 10; i++) ten[i] = ten[i - 1] * 10;
        //for (int i = 0; i < 10; i++) printf("ten:%d
    ", ten[i]);
    }
    
    int main() {
        pre();
        int tc;
        scanf("%d", &tc);
        while (tc--) {
            scanf("%s", str);
            int len = strlen(str) - 4;
            int x = 0;
            for (int i = 4; i < len + 4; i++) x = x * 10 + str[i] - '0';
            int tmp = 1989;
            for (int i = 1; i < len; i++) {
                tmp += ten[i];
            }
            if (x < tmp%ten[len]) tmp += ten[len];
            printf("%d
    ", tmp/ten[len]*ten[len]+x);
        }
        return 0;
    }
  • 相关阅读:
    二进制包安装MySQL数据库
    Nginx 访问日志轮询切割
    安装Nginx服务
    生产环境常见的HTTP状态码列表
    SSH批量部署服务
    MYSQL数据库的优化
    inotify+rsync实现实时同步部署
    rsync同步架构
    Linux shell脚本编程(三)
    Linux shell脚本编程(二)
  • 原文地址:https://www.cnblogs.com/fenice/p/5548278.html
Copyright © 2011-2022 走看看