Codeforces Round #347 (Div. 2) C. International Olympiad 找规律
题目链接:
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 找规律的更多相关文章
- codeforces Round #347 (Div. 2) C - International Olympiad
思路:从后往前一位一位的模拟,每次判断一下当前枚举的数是否之间枚举过了.或者当前枚举数过小,小于1989. #include<cstdio> #include<cstring> ...
- 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 ...
- DFS Codeforces Round #306 (Div. 2) B. Preparing Olympiad
题目传送门 /* DFS: 排序后一个一个出发往后找,找到>r为止,比赛写了return : */ #include <cstdio> #include <iostream&g ...
- Codeforces Round #347 (Div. 2)
unrating的一场CF A - Complicated GCD #include <bits/stdc++.h> const int N = 1e5 + 5; char a[105], ...
- 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 ...
- Codeforces Round #347 (Div. 2) B. Rebus
题目链接: http://codeforces.com/contest/664/problem/B 题意: 给你一个等式,把等式左边的问号用1到n(n为等式右边的数)的数填好,使得等式成立 题解: 贪 ...
- 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不可约分,如果存在多组满足 ...
- 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 ...
- Codeforces Round #347 (Div.2)_B. Rebus
题目链接:http://codeforces.com/contest/664/problem/B B. Rebus time limit per test 1 second memory limit ...
随机推荐
- Swiper之滑块1
之前介绍过Swiper,它是一个神奇的插件.类似于Android的触屏操作,Swiper应用于Web中也可以实现这样的效果,我们来看看(用鼠标可拖动). startSlide Integer (def ...
- 北大ACM(POJ1012-Joseph)
Question:http://poj.org/problem?id=1012 问题点:约瑟夫环. Memory: 220K Time: 329MS Language: C++ Result: Acc ...
- js利用数组length属性清空和截短数组
1.使用length清空数组: 代码如下 复制代码 <script> var arr1 = ['aaa','bbbb','http://www.111cn.net']; ale ...
- C# 中怎么将string转换成int型
int intA = 0;1.intA =int.Parse(str);2.int.TryParse(str, out intA);3.intA = Convert.ToInt32(str);以上都可 ...
- js选中下拉框的默认选项
//这是修改时选中 $("#type").find("option[value='"+factory+"']").attr("se ...
- 理解JavaScript设计模式与开发应用中发布-订阅模式的最终版代码
最近拜读了曾探所著的<JavaScript设计模式与开发应用>一书,在读到发布-订阅模式一章时,作者不仅给出了基本模式的通用版本的发布-订阅模式的代码,最后还做出了扩展,给该模式增加了离线 ...
- mstsc命令详解
1: 在xp sp2中用mstsc /console命令可以登录到远程桌面的控制台(和在电脑前以同一用户登录),xp升级到sp3后,不能这样用了.sp3中命令应该换成mstsc /admin. 2: ...
- 火星坐标系 (GCJ-02) 与百度坐标系 (BD-09) 的转换算法
$x_pi = 3.14159265358979324 * 3000.0 / 180.0; //火星坐标系 (GCJ-02)转百度坐标系 (BD-09)算法 function bd_encrypt($ ...
- linux服务器修改ftp默认21端口方法
1.登录服务器,打开vsftp.conf文件 # vim /etc/vsftpd/vsftpd.conf 2.在文件末尾增加listen_port=8021 #remote_charset=CP125 ...
- c#读写注册表示例分享
c#读写注册表示例,示例中有详细注释. 代码: //写注册表RegistryKey regWrite;//往HKEY_CURRENT_USER主键里的Software子键下写一个名为“Test”的子键 ...