codeforces 664C C. International Olympiad(数学)
2016-04-19 17:11
399 查看
题目链接:C. International Olympiadtime limit per test
1 secondmemory limit per test
256 megabytesinput
standard inputoutput
standard outputInternational 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.InputThe 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.OutputFor each abbreviation given in the input, find the year of the corresponding Olympiad.Examplesinput
1 secondmemory limit per test
256 megabytesinput
standard inputoutput
standard outputInternational 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.InputThe 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.OutputFor each abbreviation given in the input, find the year of the corresponding Olympiad.Examplesinput
5 IAO'15 IAO'2015 IAO'1 IAO'9 IAO'0output
2015 12015 1991 1989 1990input
4 IAO'9 IAO'99 IAO'999 IAO'9999output
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<<"\n"; 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; }
相关文章推荐
- ViewPager -- Fragment 切换卡顿 性能优化
- 自己实现String类
- Redis-3.0.7主从简单复制的配置
- bootstrap得动态进度条
- Go 数据库连接方法,配置独立
- 《C++primer》读书笔记三
- spring 不同注解的使用场景
- MediaPlayer
- 内部类的使用以及抽象类的实现
- 更新到android studio2.0后,运行时出现一个问题:Error running app: Instant Run requires 'Tools | Android | Enable AD
- JAVA虚拟机之六:虚拟机性能监控和故障处理工具
- NYOJ 30 Gone Fishing(贪心)(个人理解笔记)
- opencv里的norm范数和图像里的深度和通道数的理解和意义和相机标定后对内外参数的质量评估
- 【BZOJ3036】绿豆蛙的归宿 概率DP
- 第八周:战斗模块
- request对象和response对象的作用和相关方法
- R语言︱函数使用技巧(循环、if族/for、switch、repeat、ifelse、stopifnot)
- ubuntu下安装mysql及卸载mysql方法
- JAVA虚拟机之五:常见配置与范例
- 冲刺一