比赛的时候后缀长度在4位以内的时候分类讨论了一下,其实他们完全是一个套路的。。并不需要讨论。

然后没有考虑前导0的情况,就wa了。。


题目链接:

http://codeforces.com/problemset/problem/662/D

题意:

用年份的最短的后缀唯一的表示它,这个后缀不能在比他小的年份中使用过。

给定后缀,求年份。

分析:

长度为1的后缀可以表示10个年份。。

长度为2的后缀可以表示100个年份。。

长度为k的后缀可以表示10k个年份。。

这样加起来

到长度为k+1的后缀的时候,已经有tot=101+102+103+...+10k个年份被唯一表示过了。

所以长度为k+1的后缀可以表示的年份在1989+tot到1989+tot+10k+1−1之间。这样便可以根据后缀的位数唯一表示出年份了。。

注意前导0!

代码:

#include<iostream>
using namespace std;
int main (void)
{
int n;cin>>n;
string s;
int ans;
for(int i = 0; i < n; i++){
int q = 0;
cin>>s;
s = s.substr(4);
int len = s.length();
for(int i = 0; i < len; i++)
q = q * 10 + s[i] - '0';
int tmp = 0;
int ten = 10;
for(int i = 1; i < len; i++){
tmp += ten;
ten *= 10;
}
while(tmp + 1989 > q) q += ten;
cout<<q<<endl;
}
return 0;
}

Codeforces 662D International Olympiad【贪心】的更多相关文章

  1. CodeForces 662D International Olympiad

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

  2. codeforces 664C C. International Olympiad(数学)

    题目链接: C. International Olympiad time limit per test 1 second memory limit per test 256 megabytes inp ...

  3. codeforces 704B - Ant Man 贪心

    codeforces 704B - Ant Man 贪心 题意:n个点,每个点有5个值,每次从一个点跳到另一个点,向左跳:abs(b.x-a.x)+a.ll+b.rr 向右跳:abs(b.x-a.x) ...

  4. CodeForces - 50A Domino piling (贪心+递归)

    CodeForces - 50A Domino piling (贪心+递归) 题意分析 奇数*偶数=偶数,如果两个都为奇数,最小的奇数-1递归求解,知道两个数都为1,返回0. 代码 #include ...

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

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

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

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

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

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

  8. Codeforces 161 B. Discounts (贪心)

    题目链接:http://codeforces.com/contest/161/problem/B 题意: 有n个商品和k辆购物车,给出每个商品的价钱c和类别t(1表示凳子,2表示铅笔),如果一辆购物车 ...

  9. CodeForces 176A Trading Business 贪心

    Trading Business 题目连接: http://codeforces.com/problemset/problem/176/A Description To get money for a ...

随机推荐

  1. bzoj 4373 算术天才⑨与等差数列——线段树+set

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4373 能形成公差为k的等差数列的条件:mx-mn=k*(r-l) && 差分 ...

  2. js的Date()时间对象

    var nowDate = new Date(); nowDate.getYear(); //获取当前年份(2位) nowDate.getFullYear(); //获取完整的年份(4位,1970-? ...

  3. windows 2008 安装 apache + mysql + php

    下载准备 php : http://windows.php.net/downloads/releases/archives/ apache : https://www.apachehaus.com/c ...

  4. JavaScript中用var和不用var的区别

    Javascript声明变量的,虽然用var关键字声明和不用关键字声明,很多时候运行并没有问题,但是这两种方式还是有区别的.可以正常运行的代码并不代表是合适的代码. varnum=1; 是在当前域中声 ...

  5. R330 打印机连供墨水红灯常量处理

    墨水灯红灯常量,表示墨盒没墨水 1.按红灯,将墨盒移动到右侧空处 2.按住连供顶部的重置小按钮 15秒以上,复位(这个应该是让连供墨盒产生一个另外的墨盒序号,骗打印机换了个新墨盒) 3.按打印机红灯, ...

  6. Vue.之.路由跳转

    Vue.之.路由跳转 在进行项目开发的过程中,需要使用路由进行跳转.如下: // 不带有参数,在页面上跳转到别的页面 1. this.$router.push('/login/init');  // ...

  7. Laravel Homestead: 403 forbidden on nginx, http://homestead.app访问不了

    起因:是因为Homestead.yaml 映射失败,一般是由于没有修改sites导致的, 正确的sites设置,类似于: 而很多人吧folders的配置看成是sites的配置了 解决方法: ①按照正确 ...

  8. 2018.8.10 提高B组模拟赛

    T1 阶乘 Time Limits: 1000 ms Memory Limits: 262144 KB Detailed Limits Goto ProblemSet Description 有n个正 ...

  9. 洛谷3953 (NOIp2017) 逛公园——记忆化搜索+用栈判0环

    题目:https://www.luogu.org/problemnew/show/P3953 因为K只有50,所以想到用dp[ cr ][ j ]表示在点cr.比最短路多走了 j 的方案数.(看了TJ ...

  10. HDU 3555 (递推&&记忆化)

    #include<stdio.h> #include<string.h> #define max 25 typedef __int64 LL; LL dp[max][]; // ...