zoukankan      html  css  js  c++  java
  • codeforces 664C C. International Olympiad(数学)

    题目链接:

    C. International Olympiad

    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of formIAO'y, where y stands for some number of consequent last digits of the current year. Organizers always pick an abbreviation with non-empty string y that has never been used before. Among all such valid abbreviations they choose the shortest one and announce it to be the abbreviation of this year's competition.

    For example, the first three Olympiads (years 1989, 1990 and 1991, respectively) received the abbreviations IAO'9, IAO'0 andIAO'1, while the competition in 2015 received an abbreviation IAO'15, as IAO'5 has been already used in 1995.

    You are given a list of abbreviations. For each of them determine the year it stands for.

    Input

    The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the number of abbreviations to process.

    Then n lines follow, each containing a single abbreviation. It's guaranteed that each abbreviation contains at most nine digits.

    Output
     

    For each abbreviation given in the input, find the year of the corresponding Olympiad.

    Examples
     
    input
    5
    IAO'15
    IAO'2015
    IAO'1
    IAO'9
    IAO'0
    output
    2015
    12015
    1991
    1989
    1990
    input
    4
    IAO'9
    IAO'99
    IAO'999
    IAO'9999
    output
    1989
    1999
    2999
    9999

    题意:

    从1989年开始,每个年份都用其后缀表示,如果这个后缀被之前的年份用过了,那么后缀就往前增加一位,现在给出后缀,问它表示的是哪一年;

    思路:

    可以发现,后缀的长度是有规律的,比如一个字符的后缀表示[1989,1998]两个字符的后缀表示[1999,2098]三个字符的后缀表示[2099,3098]...
    可以发现这些区间的长度为后缀字符的个数^10;
    所以就可以先处理所有的区间,然后再在前边加上相应的前缀,看是否在这个区间内就好了;

    AC代码:

    /*2014300227    662D - 46    GNU C++11    Accepted    15 ms    2180 KB*/
    #include <bits/stdc++.h>
    using namespace std;
    const int N=1e6+5;
    typedef long long ll;
    const ll mod=1e9+7;
    ll dp[20];
    int n;
    char str[20];
    ll fun(int x)
    {
        ll ans=1;
        for(int i=1;i<=x;i++)
        {
            ans*=10;
        }
        return ans;
    }
    int solve()
    {
        int len=strlen(str);
        ll s=0;
        for(int i=4;i<len;i++)
        {
            s*=10;
            s+=str[i]-'0';
        }
        for(int i=0;i<=200;i++)
        {
            ll num=s+(ll)i*fun(len-4);
            if(num>=dp[len-5]&&num<dp[len-4])
            {
                cout<<num<<"
    ";
                return 0;
            }
        }
    }
    
    int main()
    {
        dp[0]=1989;
        ll temp=1;
        for(int i=1;i<=12;i++)
        {
            temp*=10;
            dp[i]=dp[i-1]+temp;
        }
        scanf("%d",&n);
        for(int i=0;i<n;i++)
        {
            scanf("%s",str);
            solve();
        }
        return 0;
    }


  • 相关阅读:
    windows系统设置虚拟机开机自启并运行虚拟系统
    Pycharm模板添加默认信息
    (翻译)从底层了解ASP.NET体系结构 [转]
    sql2000安装在win2003后只有在本机才能访问,局域网内其他机器不能访问
    Web上传文件的原理及实现[转]
    Http 请求处理流程[转]
    .net 必知
    sql2000数据库在企业管理器中显示置疑(suspect),在查询分析器不显示。在企业管理器中附加:提示错误823
    HTTP请求过程简介[转]
    面向对象
  • 原文地址:https://www.cnblogs.com/zhangchengc919/p/5408966.html
Copyright © 2011-2022 走看看