题目链接:

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
  1. 5
    IAO'15
    IAO'2015
    IAO'1
    IAO'9
    IAO'0
output
  1. 2015
    12015
    1991
    1989
    1990
input
  1. 4
    IAO'9
    IAO'99
    IAO'999
    IAO'9999
output
  1. 1989
    1999
    2999
    9999
  2.  
  3. 题意:
  4.  
  5. 1989年开始,每个年份都用其后缀表示,如果这个后缀被之前的年份用过了,那么后缀就往前增加一位,现在给出后缀,问它表示的是哪一年;
  6.  
  7. 思路:
  8.  
  9. 可以发现,后缀的长度是有规律的,比如一个字符的后缀表示[1989,1998]两个字符的后缀表示[1999,2098]三个字符的后缀表示[2099,3098]...
    可以发现这些区间的长度为后缀字符的个数^10;
    所以就可以先处理所有的区间,然后再在前边加上相应的前缀,看是否在这个区间内就好了;
  10.  
  11. AC代码:
  1. /*2014300227 662D - 46 GNU C++11 Accepted 15 ms 2180 KB*/
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. const int N=1e6+;
  5. typedef long long ll;
  6. const ll mod=1e9+;
  7. ll dp[];
  8. int n;
  9. char str[];
  10. ll fun(int x)
  11. {
  12. ll ans=;
  13. for(int i=;i<=x;i++)
  14. {
  15. ans*=;
  16. }
  17. return ans;
  18. }
  19. int solve()
  20. {
  21. int len=strlen(str);
  22. ll s=;
  23. for(int i=;i<len;i++)
  24. {
  25. s*=;
  26. s+=str[i]-'';
  27. }
  28. for(int i=;i<=;i++)
  29. {
  30. ll num=s+(ll)i*fun(len-);
  31. if(num>=dp[len-]&&num<dp[len-])
  32. {
  33. cout<<num<<"\n";
  34. return ;
  35. }
  36. }
  37. }
  38.  
  39. int main()
  40. {
  41. dp[]=;
  42. ll temp=;
  43. for(int i=;i<=;i++)
  44. {
  45. temp*=;
  46. dp[i]=dp[i-]+temp;
  47. }
  48. scanf("%d",&n);
  49. for(int i=;i<n;i++)
  50. {
  51. scanf("%s",str);
  52. solve();
  53. }
  54. return ;
  55. }
  1.  

codeforces 664C C. International Olympiad(数学)的更多相关文章

  1. 【23.33%】【codeforces 664C】International Olympiad

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  2. Codeforces Round #347 (Div. 2) C. International Olympiad 找规律

    题目链接: http://codeforces.com/contest/664/problem/C 题解: 这题最关键的规律在于一位的有1989-1998(9-8),两位的有1999-2098(99- ...

  3. Codeforces 662D International Olympiad【贪心】

    比赛的时候后缀长度在4位以内的时候分类讨论了一下,其实他们完全是一个套路的..并不需要讨论. 然后没有考虑前导0的情况,就wa了.. 题目链接: http://codeforces.com/probl ...

  4. codeforces Round #347 (Div. 2) C - International Olympiad

    思路:从后往前一位一位的模拟,每次判断一下当前枚举的数是否之间枚举过了.或者当前枚举数过小,小于1989. #include<cstdio> #include<cstring> ...

  5. CodeForces 662D International Olympiad

    写出前几个找规律,然后直接输出. #include<cstdio> #include<cstring> #include<cmath> #include<al ...

  6. [Codeforces 1178D]Prime Graph (思维+数学)

    Codeforces 1178D (思维+数学) 题面 给出正整数n(不一定是质数),构造一个边数为质数的无向连通图(无自环重边),且图的每个节点的度数为质数 分析 我们先构造一个环,每个点的度数都是 ...

  7. Codeforces 627 A. XOR Equation (数学)

    题目链接:http://codeforces.com/problemset/problem/627/A 题意: 告诉你s 和 x,a + b = s    a xor b = x   a, b > ...

  8. Codeforces Beta Round #2B(dp+数学)

    贡献了一列WA.. 数学很神奇啊 这个题的关键是怎么才能算尾0的个数 只能相乘 可以想一下所有一位数相乘 除0之外,只有2和5相乘才能得到0 当然那些本身带0的多位数 里面肯定含有多少尾0 就含有多少 ...

  9. codeforces 803C Maximal GCD(GCD数学)

    Maximal GCD 题目链接:http://codeforces.com/contest/803/problem/C 题目大意: 给你n,k(1<=n,k<=1e10). 要你输出k个 ...

随机推荐

  1. DevExpress的GridControl如何实现打印和打印预览 z

    第一种方法:             System.Drawing.Printing.PageSettings set_print_page = new System.Drawing.Printing ...

  2. 【转载】面向切面编程(AOP)学习

    看到这篇文章,学习一下:http://www.ciaoshen.com/2016/10/28/aop/ 想理清一下从“动态代理”,到 “注释”,到“面向切面编程”这么一个技术演进的脉络. 只想讲清楚两 ...

  3. 两点C#的propertyGrid的使用心得【转】

    源文:http://www.cnblogs.com/bicker/p/3318934.html 最近接触C#的PropertyGrid比较多,得到了两个小心得记录一下. 第1点是关于控制Propert ...

  4. Android API Guides---Services

    服务 在该文献 基础 声明在清单服务 创建一个启动的服务 扩展IntentService类 扩展服务类 启动服务 停止服务 创建绑定服务 将通知发送给用户 执行在前台服务 管理服务生命周期 实施生命周 ...

  5. WinDbg抓取dmp文件

    应用程序发生异常时抓取dmp: adplus.vbs -crash -pn w3wp.exe -y srv*c:\symbols*http://msdl.microsoft.com/download/ ...

  6. MyEclipse 设置智能提示

    choice 1: -->window→Preferences→Java→Editor→Content Assist, --->将Auto activation delay 的数值改为一个 ...

  7. SGPIO

    http://en.wikipedia.org/wiki/SGPIO SGPIO From Wikipedia, the free encyclopedia   Serial General Purp ...

  8. uboot下载地址

    非常奇怪百度搜索都搜不到一个好的uboot下载的说明,仅此标记 HOME http://www.denx.de/wiki/U-Boot/SourceCode sourcecode http://www ...

  9. codeforces 557 C

    由于期末.非常久没刷题了,CF一直掉-- 这个题事实上非常简单. .由于做法非常easy想到嘛.. 就是枚举max=x时,最大能保留多少价值.不断更新ans, 结果就是全部价值和减去ans就好 因为最 ...

  10. 【BZOJ4293】[PA2015]Siano 线段树

    [BZOJ4293][PA2015]Siano Description 农夫Byteasar买了一片n亩的土地,他要在这上面种草. 他在每一亩土地上都种植了一种独一无二的草,其中,第i亩土地的草每天会 ...