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 ...
随机推荐
- SSH密钥验证
基于密钥验证 1. 在客户端生成密钥对 可以先进入用户的.ssh 目录 cd ~/.ssh ssh-keygen -t rsa [-P '' ] [-f "~/.ssh/id_rsa&quo ...
- 【PHP】什么时候使用Try Catch(转)
几条建议: 如果无法处理某个异常,那就不要捕获它. 如果捕获了一个异常,请不要胡乱处理它. 尽量在靠近异常被抛出的地方捕获异常. 在捕获异常的地方将它记录到日志中,除非您打算将它重新抛出. 按 ...
- Python装饰器使用规范案例详解
由于函数也是一个对象,而且函数对象可以被赋值给变量,所以,通过变量也能调用该函数. >>> def now(): ... print('2015-3-25') ... >> ...
- A1046 Shortest Distance (20)(20 分)
1046 Shortest Distance (20)(20 分)提问 The task is really simple: given N exits on a highway which form ...
- mysql-update时where条件无索引锁全表
1 5.3日数据处理需求 UPDATE md_meter set warranty_end_date = DATE_ADD(warranty_begin_date,INTERVAL 10 ...
- 2 - JVM随笔分类(JVM堆的内存回收)
JVM常用的回收算法是: 标记/清除算法 标记/复制算法 标记/整理算法 其中上诉三种算法都先具备,标记阶段,通过标记阶段,得到当前存活的对象,然后再将非标记的对象进行清除,而对象内存中对象的标记过程 ...
- 设计模式之第8章-策略模式(Java实现)
设计模式之第8章-策略模式(Java实现) “年前大酬宾了啊,现在理发冲500送300,冲1000送500了.鱼哥赶紧充钱啊,理发这事基本一个月一回,挺实惠的啊.不过话说那个理发店的老板好傻啊,冲10 ...
- MoveWindow() SetWindowPos()的区别与联系
敲代码时,突然发现有一个背景图片无法显示,百思不得其解,最终发现是MoveWindow() SetWindowPos()这两个函数的使用不当造成的. 这里把这两个函数的前世今生给分析一下. 先看Mov ...
- @SpringBootApplication的扫描范围
在公共类自定义一个全局异常类,实现全局捕获异常,在另一个服务中调用的时候,发现没有生效 因此我添加了一个@ComponentScan("com.wuhen.jwt.common") ...
- python-day4-内置函数2
摘要:python中有好多可用性特别强的内置函数,熟练掌握对于以后的编程过程中有很大的帮助~~~~ callable函数.chr函数与ord函数.random函数.compile函数.evec与eva ...