codeforces 664C C. International Olympiad(数学)
题目链接:
1 second
256 megabytes
standard input
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.
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.
For each abbreviation given in the input, find the year of the corresponding Olympiad.
5
IAO'15
IAO'2015
IAO'1
IAO'9
IAO'0
2015
12015
1991
1989
1990
4
IAO'9
IAO'99
IAO'999
IAO'9999
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+;
typedef long long ll;
const ll mod=1e9+;
ll dp[];
int n;
char str[];
ll fun(int x)
{
ll ans=;
for(int i=;i<=x;i++)
{
ans*=;
}
return ans;
}
int solve()
{
int len=strlen(str);
ll s=;
for(int i=;i<len;i++)
{
s*=;
s+=str[i]-'';
}
for(int i=;i<=;i++)
{
ll num=s+(ll)i*fun(len-);
if(num>=dp[len-]&&num<dp[len-])
{
cout<<num<<"\n";
return ;
}
}
} int main()
{
dp[]=;
ll temp=;
for(int i=;i<=;i++)
{
temp*=;
dp[i]=dp[i-]+temp;
}
scanf("%d",&n);
for(int i=;i<n;i++)
{
scanf("%s",str);
solve();
}
return ;
}
codeforces 664C C. International Olympiad(数学)的更多相关文章
- 【23.33%】【codeforces 664C】International Olympiad
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- Codeforces Round #347 (Div. 2) C. International Olympiad 找规律
题目链接: http://codeforces.com/contest/664/problem/C 题解: 这题最关键的规律在于一位的有1989-1998(9-8),两位的有1999-2098(99- ...
- Codeforces 662D International Olympiad【贪心】
比赛的时候后缀长度在4位以内的时候分类讨论了一下,其实他们完全是一个套路的..并不需要讨论. 然后没有考虑前导0的情况,就wa了.. 题目链接: http://codeforces.com/probl ...
- codeforces Round #347 (Div. 2) C - International Olympiad
思路:从后往前一位一位的模拟,每次判断一下当前枚举的数是否之间枚举过了.或者当前枚举数过小,小于1989. #include<cstdio> #include<cstring> ...
- CodeForces 662D International Olympiad
写出前几个找规律,然后直接输出. #include<cstdio> #include<cstring> #include<cmath> #include<al ...
- [Codeforces 1178D]Prime Graph (思维+数学)
Codeforces 1178D (思维+数学) 题面 给出正整数n(不一定是质数),构造一个边数为质数的无向连通图(无自环重边),且图的每个节点的度数为质数 分析 我们先构造一个环,每个点的度数都是 ...
- Codeforces 627 A. XOR Equation (数学)
题目链接:http://codeforces.com/problemset/problem/627/A 题意: 告诉你s 和 x,a + b = s a xor b = x a, b > ...
- Codeforces Beta Round #2B(dp+数学)
贡献了一列WA.. 数学很神奇啊 这个题的关键是怎么才能算尾0的个数 只能相乘 可以想一下所有一位数相乘 除0之外,只有2和5相乘才能得到0 当然那些本身带0的多位数 里面肯定含有多少尾0 就含有多少 ...
- codeforces 803C Maximal GCD(GCD数学)
Maximal GCD 题目链接:http://codeforces.com/contest/803/problem/C 题目大意: 给你n,k(1<=n,k<=1e10). 要你输出k个 ...
随机推荐
- 邁向IT專家成功之路的三十則鐵律 鐵律三:IT人長久之道–站對邊
這一回來談談IT人對於技術的學習.對於一位專業的IT人來說,在自己有興趣的技術領域之中,究竟要如何來正確選擇學習的方向呢?關於這個問題的答案,筆者個人深深體會到這確實會成為一位專業IT人士的長久經營之 ...
- intellij idea 的常用有用快捷键
ctrl + R:替换(这一点和office 中的ctrl + H不一样) ctrl + alt + L:自动整理代码(不会整理注释文件) ctrl + alt:(自动导入包,不能批量导入,有人评论批 ...
- [Javascript] Await a JavaScript Promise in an async Function with the await Operator
The await operator is used to wait for a promise to settle. It pauses the execution of an async func ...
- PS 基础知识 如何绘制几何图形
注意:规则的几何图形必须用路径工具,如果使用简单的椭圆工具再描边,则效果是像素堆砌起来的.图像一旦放大就是出现明显的失真. 使用钢笔工具,然后选择路径工具,然后选择需要绘制的图形. 如果需要找 ...
- sql server 2008出现远程过程调用失败
sql server 2008出现远程过程调用失败解决方式有下面几种: 1.依照网上说的方法.是由于装了vs 2012或是vs2013或是vs2015等高版本号时.安装了Microsoft SQL ...
- vue2.0 + vux (四)Home页
1.综合页(首页) Home.vue <!-- 首页 --> <template> <div> <!-- 顶部 标题栏 --> <app-head ...
- valid-palindrome——判断带符号数字字母的字符串是否为回文
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- python 大小写转换方法(全)
http://blog.csdn.net/liuxincumt/article/details/7945337 python大小写转换(全)
- bootstrap table api
http://blog.csdn.net/rickiyeat/article/details/56483577
- IOS UIWebView 随记
UIWebView中加载的网页尺寸太大,如何让网页适应屏幕大小 webview.scalesPageToFit = YES;