Codeforces Round #555 (Div. 3) B. Long Number 【仔细读题】
2 seconds
256 megabytes
standard input
standard output
You are given a long decimal number aa consisting of nn digits from 11 to 99. You also have a function ff that maps every digit from 11 to 99 to some (possibly the same) digit from 11 to 99.
You can perform the following operation no more than once: choose a non-empty contiguous subsegment of digits in aa, and replace each digit xx from this segment with f(x)f(x). For example, if a=1337a=1337, f(1)=1f(1)=1, f(3)=5f(3)=5, f(7)=3f(7)=3, and you choose the segment consisting of three rightmost digits, you get 15531553 as the result.
What is the maximum possible number you can obtain applying this operation no more than once?
The first line contains one integer nn (1≤n≤2⋅1051≤n≤2⋅105) — the number of digits in aa.
The second line contains a string of nn characters, denoting the number aa. Each character is a decimal digit from 11 to 99.
The third line contains exactly 99 integers f(1)f(1), f(2)f(2), ..., f(9)f(9) (1≤f(i)≤91≤f(i)≤9).
Print the maximum number you can get after applying the operation described in the statement no more than once.
4
1337
1 2 5 4 6 6 3 1 9
1557
5
11111
9 8 7 6 5 4 3 2 1
99999
2
33
1 1 1 1 1 1 1 1 1
33
题意:在字符串中任意选择一个子串,将该子串中的数字按照题目的替换规则进行替换(无论替换之后,新数字比旧数字大还是小,只要在字串范围之内都要替换),找出替换后的最大数字;
这个数字替换是在字符串的某一段区间的,在这段区间中所有的就数字都要被新数字替换,所以我们最先找到的子串(其中替换后的新数字都比就数字大,遇到新数字比旧数字小,就停止),就可以的得到最大数字
错因:一开始以为替换区间是整个字符串,然后按照新数字比就数字大就替换,新数字比就数字小就不替换,然后 WA6了。
#include<stdio.h>
#include<string>
#include<string.h>
using namespace std; int n,num[],judge[];
char m[];
int main(){
scanf("%d",&n);getchar();
for(int i = ; i <= n ; i++){
scanf("%c",&m[i]);
}
for(int i = ; i <= n ; i++){
num[i] = m[i] - ;
}
int cnt = n;
for(int i = ; i <= ; i++){
scanf("%d",&judge[i]);
}
int ret = ;
for(int i = ; i <= n ; i++){
if(ret == && judge[num[i]] < num[i]){
ret++;
}
if(judge[num[i]] > num[i] && ret == ){
num[i] = judge[num[i]];
ret = ;
}else if(judge[num[i]] > num[i] && ret == ){
num[i] = judge[num[i]];
} printf("%d",num[i]);
}
printf("\n");
return ;
}
AC代码
一个从很久以前就开始做的梦。
Codeforces Round #555 (Div. 3) B. Long Number 【仔细读题】的更多相关文章
- Codeforces Round #297 (Div. 2)A. Vitaliy and Pie 水题
Codeforces Round #297 (Div. 2)A. Vitaliy and Pie Time Limit: 2 Sec Memory Limit: 256 MBSubmit: xxx ...
- Codeforces Round #298 (Div. 2) A、B、C题
题目链接:Codeforces Round #298 (Div. 2) A. Exam An exam for n students will take place in a long and nar ...
- Codeforces Round #281 (Div. 2) B. Vasya and Wrestling 水题
B. Vasya and Wrestling 题目连接: http://codeforces.com/contest/493/problem/B Description Vasya has becom ...
- 老年OIer的Python实践记—— Codeforces Round #555 (Div. 3) solution
对没错下面的代码全部是python 3(除了E的那个multiset) 题目链接:https://codeforces.com/contest/1157 A. Reachable Numbers 按位 ...
- Codeforces Round #427 (Div. 2) B. The number on the board
引子: A题过于简单导致不敢提交,拖拖拉拉10多分钟还是决定交,太冲动交错了CE一发,我就知道又要错过一次涨分的机会.... B题还是过了,根据题意目测数组大小开1e5,居然蒙对,感觉用vector更 ...
- Codeforces Round #585 (Div. 2) B. The Number of Products(DP)
链接: https://codeforces.com/contest/1215/problem/B 题意: You are given a sequence a1,a2,-,an consisting ...
- CodeForces Round #555 Div.3
A. Reachable Numbers 代码: #include <bits/stdc++.h> using namespace std; ; int N; set<int> ...
- Codeforces Round #555 (Div. 3) AB
A: http://codeforces.com/contest/1157/problem/A 题意:每次加到10的整数倍之后,去掉后面的0,问最多有多少种可能. #include <io ...
- Codeforces Round #555 (Div. 3)[1157]题解
不得不说这场div3是真的出的好,算得上是从我开始打开始最有趣的一场div3.因为自己的号全都蓝了,然后就把不经常打比赛的dreagonm的号借来打这场,然后...比赛结束rank11(帮dreago ...
随机推荐
- Ubuntu 14.04 安装 Dash to Dock
每次打开或选择一个已经打开的应用都要把鼠标指到左上角,相当费事. Ubuntu 14.04 GNOME自带 Tweaks (系统中名为:优化工具),可以使界面如Windows般(最小化.最大化.底部任 ...
- POJ 2155 二维线段树 经典的记录所有修改再统一遍历 单点查询
本来是想找一个二维线段树涉及懒惰标记的,一看这个题,区间修改,单点查询,以为是懒惰标记,敲到一半发现这二维线段树就不适合懒惰标记,你更新了某段的某列,但其实其他段的相应列也要打标记,但因为区间不一样, ...
- Spark 内存管理
Spark 内存管理 Spark 执行应用程序时, 会启动 Driver 和 Executor 两种 JVM 进程 Driver 负责创建 SparkContext 上下文, 提交任务, task的分 ...
- java基础源码 (4)--reflect包-AnnotatedElement接口
接口:AnnotatedElement * Represents an annotated element of the program currently running in this * VM. ...
- POJ 3311 Hie with the Pie 最短路+状压DP
Hie with the Pie Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 11243 Accepted: 5963 ...
- vue小练习--音乐播放器
1 首先建一个文件夹 放几首歌曲 2 看代码 1)基本版本 <!DOCTYPE html> <html lang="zh-CN"> <head> ...
- 使用SSH工具连接WSL
简单记录下操作过程 我在微软应用商店下载了Ubuntu 18.04 LTS.但是Windows的命令行太丑,我打算使用SSH工具连接WSL,输入密码一直拒绝连接... 查找资料之后解决了这个问题 双击 ...
- 使用BP拦截POST型请求包 (9.20 第九天)
使用BP拦截POST型请求包 1.安装phpstudy并下载wordpress 文件,安装在phpstudy的www目录下 phpstudy下载地址:https://www.xp.cn/downloa ...
- HDU 5280 BestCoder Round #47 1001:Senior's Array
Senior's Array Accepts: 199 Submissions: 944 Time Limit: 2000/1000 MS (Java/Others) Memory Limit ...
- EUI库 - 10 - 使用自定义组件
步骤 1 在根节点,添加一个自定义的命名空间 2 可以设置skinName 自定义组件规范 1 不复用的不要用自定义组件 2 属性必须要有默认值(赋值为null也可以),因为TS编译器会把没有默 ...