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个 ...
随机推荐
- Ubuntu下添加开机启动项的2种方法
1.方法一,编辑rc.loacl脚本 Ubuntu开机之后会执行/etc/rc.local文件中的脚本,所以我们可以直接在/etc/rc.local中添加启动脚本.当然要添加到语句:exit 0 前面 ...
- 为什么硬盘明明还有空间,linux却说硬盘空间不足?inode;mkdir: 无法创建目录"shen1": 设备上没有空间
现象:df -h显示硬盘还有14G空间,但是touch file/mkdir directory都失败,提示硬盘没有空间 原因:df -ia查看下inode的使用情况,发现已经爆了,(下图显示使用88 ...
- SilverLight:布局(3)StackPanel 对象
ylbtech-SilverLight-Layout: 布局(3)StackPanel 对象 A, Nesting Layout Containers(内嵌布局容器) B, StackPanel(队列 ...
- EasyHook库系列使用教程之四钩子的启动与停止
此文的产生花费了大量时间对EasyHook进行深入了解同一时候參考了大量文档 先来简单比較一下EasyHook与Detour钩取后程序流程 Detours:钩取API函数后.产生两个地址,一个地址相应 ...
- vscode格式化代码无效--可能的解决方法
因为vscode默认启用了根据文件类型自动设置tabsize的选项,因此,可以通过关闭自动设置选项,防止格式覆盖.在用户设置里添加如下配置即可: "editor.detectIndentat ...
- XPath可以快速定位到Xml中的节点或者属性。XPath语法很简单,但是强大够用,它也是使用xslt的基础知识。
示例Xml: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 <?xml versio ...
- 醒醒吧少年,只用Cucumber不能帮助你BDD
转载:http://insights.thoughtworkers.org/bdd/ 引言 在Ruby社区中,测试和BDD一直是被热议的话题,不管是单元测试.集成测试还是功能测试,你总能找到能帮助你的 ...
- Android 适配器教程 (六)
我们的适配器学习已经接近尾声了.尽管这不是一个大问题,可是确实是值得学习的一块知识,回忆一下之前五讲的知识.我们已经学到了非常多东西了. 在之前五讲中.我们已经由浅入深的认识了适配器,从最简单的Lis ...
- 第十六周 项目三-max带来的冲突
分析以下程序出现的编译错误,给出解决的方案. #include<iostream> using namespace std; //定义函数模板 template<class T> ...
- POCO类
我认为POCO(简单传统CLR对象)重点应该是简单,不跟其他不相关的类进行关联关系或不相关的属性.<NHibernate 4 Beginner Guid>这本书有提到,应该是满足下面三个条 ...