题目链接:

http://codeforces.com/contest/664/problem/C

题解:

这题最关键的规律在于一位的有1989-1998(9-8),两位的有1999-2098(99-98),三位的有2099-3098(099-098),四位的有3099-13098(3099-3098)

所以关键字长度一样的会连续出现,1989+0代表一位的开始,1989+10代表两位的开始,1989+10+100代表三位的开始,

现在给你一个长度为len的标志,就可以找出该数位的起始位置1989+10+100+...+10^(len-1),终止位置为1989+10+100+...+10^len-1,这个数位里面前len位固定的数是唯一的,完全可以马上找到。

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std; char str[]; int ten[];
void pre() {
ten[] = ;
for (int i = ; i < ; i++) ten[i] = ten[i - ] * ;
//for (int i = 0; i < 10; i++) printf("ten:%d\n", ten[i]);
} int main() {
pre();
int tc;
scanf("%d", &tc);
while (tc--) {
scanf("%s", str);
int len = strlen(str) - ;
int x = ;
for (int i = ; i < len + ; i++) x = x * + str[i] - '';
int tmp = ;
for (int i = ; i < len; i++) {
tmp += ten[i];
}
if (x < tmp%ten[len]) tmp += ten[len];
printf("%d\n", tmp/ten[len]*ten[len]+x);
}
return ;
}

Codeforces Round #347 (Div. 2) C. International Olympiad 找规律的更多相关文章

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

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

  2. Codeforces Round #327 (Div. 2) C. Median Smoothing 找规律

    C. Median Smoothing Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/p ...

  3. DFS Codeforces Round #306 (Div. 2) B. Preparing Olympiad

    题目传送门 /* DFS: 排序后一个一个出发往后找,找到>r为止,比赛写了return : */ #include <cstdio> #include <iostream&g ...

  4. Codeforces Round #347 (Div. 2)

    unrating的一场CF A - Complicated GCD #include <bits/stdc++.h> const int N = 1e5 + 5; char a[105], ...

  5. Codeforces Round #306 (Div. 2) B. Preparing Olympiad dfs

    B. Preparing Olympiad Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/550 ...

  6. Codeforces Round #347 (Div. 2) B. Rebus

    题目链接: http://codeforces.com/contest/664/problem/B 题意: 给你一个等式,把等式左边的问号用1到n(n为等式右边的数)的数填好,使得等式成立 题解: 贪 ...

  7. Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises)

    A. Fraction 题目链接:http://codeforces.com/contest/854/problem/A 题目意思:给出一个数n,求两个数a+b=n,且a/b不可约分,如果存在多组满足 ...

  8. Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) D. Jury Meeting(双指针模拟)

    D. Jury Meeting time limit per test 1 second memory limit per test 512 megabytes input standard inpu ...

  9. Codeforces Round #347 (Div.2)_B. Rebus

    题目链接:http://codeforces.com/contest/664/problem/B B. Rebus time limit per test 1 second memory limit ...

随机推荐

  1. DWZ (JUI) 教程 根据ID刷新 dialog

    reloadDialog:function(dialogId){ var dialog = $("body").data(dialogId); if(dialog){ $.pdia ...

  2. Linux下用freetds连接mssql中文乱码的问题【参考1】

    由于工作原因我们需要通过php访问我们以前的Sql Server 2005数据,所以就有了这篇文章的诞生.废话就少说了,做程序设计的最不喜欢兜圈子了.用简介步骤说明问题,往下看.系统:   Linux ...

  3. ASP.NET 窗体间传值实现方法详解

    假设ParentForm.aspx 页面上有TextBox1文本框和Open按钮点击Open按钮弹出SubForm.aspx,SubForm.aspx页面上有TextBox1文本框和Close按钮点击 ...

  4. 【学习笔记】【C语言】数组

    1. 什么是数组 数组,从字面上看,就是一组数据的意思,没错,数组就是用来存储一组数据的 2. 数组的特点 只能存放一种类型的数据,比如int类型的数组.float类型的数组 里面存放的数据称为“元素 ...

  5. JS学习第三课

    写表格时最好自己写上<tbody>,因为在JS里面要用,要不然html里没有,但是我们在JS里面用得飞起,也说不过去啊. 获取表格元素时,tBodis[0]一定要加上,本人试过不加,然后就 ...

  6. 杭电ACM2058--The sum problem

    http://acm.hdu.edu.cn/showproblem.php?pid=2058 以为简单的穷举就完了,结果是一直Time Limit Exceeded.. 这是代码: #include ...

  7. DataGrid3

    a标签,DataGrid的数据绑定 1.function aa(id, url) {            //alert(id);            window.open(url + '&am ...

  8. JS事件冒泡与捕获

    1事件传播——冒泡与捕获 默认情况下,事件使用冒泡事件流,不使用捕获事件流.然而,在Firefox和Safari里,你可以显式的指定使用捕获事件流,方法是在注册事件时传入useCapture参数,将这 ...

  9. android网络编程

    android的网络编程分为2种:基于socket的,和基于http协议的. 基于socket的用法 服务器端: 先启动一个服务器端的socket     ServerSocket svr = new ...

  10. 判断不在Update Task中

    CALL FUNCTION 'TH_IN_UPDATE_TASK'   IMPORTING     IN_UPDATE_TASK = IN_UPDATE_TASK.  "0 then not ...