Codeforces Round #449 Div. 2 A B C (暂时)
A. Scarborough Fair
题意
对给定的长度为\(n\)的字符串进行\(m\)次操作,每次将一段区间内的某一个字符替换成另一个字符。
思路
直接模拟
Code
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int main() {
int n, m, s,t ; char c1, c2;
char ss[110];
scanf("%d%d", &n, &m);
scanf("%s", ss+1);
for (int i = 0; i < m; ++i) {
scanf("%d%d %c %c", &s, &t, &c1, &c2);
for (int j = s; j <= t; ++j) {
if (ss[j] == c1) ss[j] = c2;
}
}
printf("%s\n", ss+1);
return 0;
}
B. Chtholly's request
题意
定义\(zcy\ number\)为长度为偶数的回文的数字,对于给定的\(k\)和\(p\),求出最小的\(k\)个\(zcy\ number\)的数的和\(\mod p\)的值(\(k\leq 1e5, p\leq 1e9\))
思路
稍微估算一下,
长度为\(2\)的有\(9\)个,
长度为\(4\)的有\(90\)个,
长度为\(6\)的有\(900\)个,
……
好的,题目要求的所有的\(zcy\ number\)都在\(long\ long\)范围内,接下来就随便怎么做了。
可直接生成。用数组。每次从中间往两边增。
Code
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int k, p, ans[20];
LL num(int* ans, int tot) {
LL ret = 0;
for (int i = (tot<<1); i >= 1; --i) (ret *= 10) += ans[i];
return ret % p;
}
int main() {
scanf("%d %d", &k, &p);
ans[2] = ans[1] = 1;
LL sum = 11 % p, tot = 1;
for (int i = 1; i < k; ++i) {
int temp = tot;
while (temp >= 1 && ans[temp] == 9) {
ans[(tot<<1)-temp+1] = ans[temp] = 0;
--temp;
}
if (!temp) {
++tot;
ans[1] = ans[tot<<1] = 1;
}
else ++ans[temp], ++ans[(tot<<1)-temp+1];
(sum += num(ans, tot)) %= p;
}
printf("%I64d\n", sum);
return 0;
}
C. Nephren gives a riddle
题意
有递推式
\(f_0=s\)
\(f_i=Af_{i-1}Bf_{i-1}C\)
问\(f_n\)的第\(k\)位上的字符
\(n\leq 1e5, k\leq 1e18\)
思路
定义\(l_i\)为\(f_i\)的长度,则\(l_i=2*l_{i-1}+l_A+l_B+l_C\),可以据此估算一下,\(l_{53} = 1288029493427961788\),这就是考虑的上限了。
\(n\)的值那么大完全就是唬人的,预处理一下即可。
因为当\(n\gt 53\)时,有意义的部分必然形如\(AA...Af_{53}\)(前面是\(n-53\)个\(A\)),只需判断答案是落在前面的\(A\)中还是后面的\(f_{53}\)中即可。
再考虑问题本身,是个很优美的递归的形式。
可以写个优美的循环_(:з」∠)_
记\(len1=f_n,len2=f_{n-1}\)
\(k\gt len1\rightarrow\)无解
\(k\leq l_A\rightarrow\)答案在\(A\)中
\(l_A+len2\lt k\leq l_A+len2+l_B\rightarrow\)答案在\(B\)中
\(k\gt len1-l_C\rightarrow\)答案在\(C\)中
其他情况\(\rightarrow\)答案在\(f_{n-1}\)中
Code
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
char s[110] = "What are you doing at the end of the world? Are you busy? Will you save us?";
char A[110] = "What are you doing while sending \"";
char B[110] = "\"? Are you busy? Will you send \"";
char C[110] = "\"?";
int l1 = 34, l2 = 32, l3 = 2;
LL arr[60] = {75,218,504,1076,2220,4508,9084,18236,36540,73148,146364,292796,585660,1171388,2342844,4685756,9371580,18743228,37486524,74973116,149946300,299892668,599785404,1199570876,2399141820,4798283708,9596567484,19193135036,38386270140,76772540348,153545080764,307090161596,614180323260,1228360646588,2456721293244,4913442586556,9826885173180,19653770346428,39307540692924,78615081385916,157230162771900,314460325543868,628920651087804,1257841302175676,2515682604351420,5031365208702908,10062730417405884,20125460834811836,40250921669623740,80501843339247548,161003686678495164,322007373356990396,644014746713980860,1288029493427961788};
int main() {
int q;
scanf("%d", &q);
while (q--) {
int n; LL k;
scanf("%d%I64d", &n, &k);
if (n > 53) {
LL len = (n-53) * l1;
if (k <= len) {
k = (k-1) % l1 + 1;
cout << A[k-1]; continue;
}
else {
k -= len;
n = 53;
}
}
if (k > arr[n]) { cout << '.'; continue; }
while (true) {
if (n == 0) { cout << s[k-1]; break; }
LL len1 = arr[n], len2 = arr[n-1];
if (k <= l1) { cout << A[k-1]; break; }
else if (k >= len1-l3+1) { cout << C[k-len1+l3-1]; break; }
else if (k > l1+len2 && k <= l1+len2+l2) { cout << B[k-l1-len2-1]; break; }
else {
--n;
if (k <= l1+len2) k -= l1;
else k -= (l1+len2+l2);
}
}
}
puts("");
return 0;
}
Codeforces Round #449 Div. 2 A B C (暂时)的更多相关文章
- Codeforces Round #449 (Div. 2)
Codeforces Round #449 (Div. 2) https://codeforces.com/contest/897 A #include<bits/stdc++.h> us ...
- Codeforces Round #449 (Div. 2)ABCD
又掉分了0 0. A. Scarborough Fair time limit per test 2 seconds memory limit per test 256 megabytes input ...
- Codeforces Round #449 (Div. 2) B. Chtholly's request【偶数位回文数】
B. Chtholly's request time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- Codeforces Round #449 (Div. 2)-897A.Scarborough Fair(字符替换水题) 897B.Chtholly's request(处理前一半) 897C.Nephren gives a riddle(递归)
A. Scarborough Fair time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #449 (Div. 2) D. Ithea Plays With Chtholly
题目链接 交互题. 题意:给你三个数n,m,k.让你完成至多m次互动,每次给你一个q,让你从n个位置选一个位置放这个数,覆盖已经放过的数.让你再m次使得n个位置的数不递减,达到直接退出. 解法:暴力, ...
- Codeforces Round #449 Div. 1
B:注意到nc/2<=m,于是以c/2为界决定数放在左边还是右边,保证序列满足性质的前提下替换掉一个数使得其更靠近边界即可. #include<iostream> #include& ...
- Codeforces Round #449 (Div. 1) Willem, Chtholly and Seniorious (ODT维护)
题意 给你一个长为 \(n\) 的序列 \(a_i\) 需要支持四个操作. \(1~l~r~x:\) 把 \(i \in [l, r]\) 的 \(a_i\) 加 \(x\) . \(2~l~r~x: ...
- Codeforces Round #449 (Div. 1)C - Willem, Chtholly and Seniorious
ODT(主要特征就是推平一段区间) 其实就是用set来维护三元组,因为数据随机所以可以证明复杂度不超过O(NlogN),其他的都是暴力维护 主要操作是split,把区间分成两个,用lowerbound ...
- Codeforces Round #449 (Div. 2) C. DFS
C. Nephren gives a riddle time limit per test 2 seconds memory limit per test 256 megabytes input st ...
随机推荐
- CentOS Linux release 7.6.1810全新安装 Zimbra 8.8.12邮箱
1.1 基础环境配置 1.1.1 主机名配置 [root@mail ~]# hostnamectl --static set-hostname mail.example.com [root@mai ...
- HDwiki 源代码 - 互动百科开源
昨日3.15,在曝光的企业中出现了一家让我好奇的企业(互动百科),一直不敢想百科能独立出来做成一家公司.出于对网站的好奇,今日进入该网站,惊讶的是此公司已经上市(股票代码:835799),在网站的底部 ...
- python3 练习题100例 (十三)
题目十三:将一个正整数分解质因数.例如:输入60,打印出60=2*2*3*5. #!/usr/bin/env python3 # -*- coding: utf-8 -*- ""& ...
- Spark性能优化:shuffle调优
调优概述 大多数Spark作业的性能主要就是消耗在了shuffle环节,因为该环节包含了大量的磁盘IO.序列化.网络数据传输等操作.因此,如果要让作业的性能更上一层楼,就有必要对shuffle过程进行 ...
- 初识java,编写hello world语句
JDK: Java Develpment Kit - java开发工具包 JRE: Java Runtime Environment - java运行环境 JVM: Java Virtual Mach ...
- Android通过AIDL和反射调用系统拨打电话和挂断电话
首先在项目中添加ITelephony.aidl文件,我的如下: /* * Copyright (C) 2007 The Android Open Source Project * * Licensed ...
- Redis实现之复制(二)
PSYNC命令的实现 在Redis实现之复制(一)这一章中,我们介绍了PSYNC命令和它的工作机制,但一直没有说明PSYNC命令的参数以及返回值.现在,我们了解了运行ID.复制偏移量.复制积压缓冲区以 ...
- Beats、Filebea入门
1. Filebeat配置简介 2. Filebeat收集nginx日志 3. packetbeat简介与演示
- HashMap 简介
HashMap 前置条件 了解数组 了解链表 jdk version: 1.8 个人分3步来了解HashMap 通过数据结构图 通过为了完成这样的数据结构我们该怎么做 HashMap 实际put方法源 ...
- Android资源限定符
Android系统会根据设备参数,自动选择最佳资源配置方案. Android中常见的资源限定符: 屏幕特征 限定符 描述 大小 small 提供给小屏幕设备的资源 normal 提供给中等屏幕设备的资 ...