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 ...
随机推荐
- 三、ReactJS、jsx、 Component 特性
reactjs特性: 基于组件(Component)化思考 用 JSX 进行声明式(Declarative)UI 设计 使用 Virtual DOM Component PropType 错误校对机制 ...
- spring源码 HierarchicalBeanFactory接口
HierarchicalBeanFactory 表示的是这些 Bean 是有继承关系的,也就是每个Bean 有可能有父 Bean. /* * Copyright 2002-2012 the origi ...
- python爬取网页文本、图片
从网页爬取文本信息: eg:从http://computer.swu.edu.cn/s/computer/kxyj2xsky/中爬取讲座信息(讲座时间和讲座名称) 注:如果要爬取的内容是多页的话,网址 ...
- elasticsearch下载与安装
目录 安装之前 下载 安装 测试 安装之前 必须注意的是:安装路径不允许有中文及空格和非法字符,尤其是中文 下载 打开elasticsearch官网.选择免费试用. 选择对应产品与版本(选择6.5.4 ...
- Day2-T2
原题目 Describe:贪心,保证至少一条路牛的数量最多 code: #include<bits/stdc++.h> using namespace std; long long n,m ...
- Maven:Unable to import maven project: See logs for details
一.开发环境 idea2019.1 + apache-maven-3.6.2 + JDK 1.8.0_111 二.问题说明 导入maven 多模块工程之后,发现工程没有多模块的展开,而且也没有在 Ex ...
- Win7 node多版本管理gnvm采坑记录
采坑描述:下载新node版本及切换node失败 解决:1.要用管理员权限启动cmd:2.确保node是空闲的 Gnvm下载地址: 32-bit | 64-bit Github 1.下载之后为 得到一个 ...
- 带你探索关于飞机Wi-Fi服务的神奇科学
资料来源: Colin Anderson制片公司/ Getty图片社 在35000英尺的高空冲浪?哇哦,这当然是我们现在所期望的飞行方式了.根据2018年全球旅行者研究(2018 Global Tra ...
- element穿梭框el-transfer增加拖拽排序和shift多选checkbox功能
<template> <div class="demo"> <el-transfer v-model="value" filter ...
- PAT Advanced 1034 Head of a Gang (30) [图的遍历,BFS,DFS,并查集]
题目 One way that the police finds the head of a gang is to check people's phone calls. If there is a ...