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 ...
 
随机推荐
- 121-PHP类成员函数(二)
			
<?php class ren{ //定义人类 const name='ren'; public function classname(){ echo '这个类的名称:'.self::name; ...
 - unicode字符等价探究
			
Demobaidu.com(\uff41)能跳转到baidu.combаidu.com(\u0430)不能跳转到baidu.com,被认为成一个其他域名 等价原因两个不同编码的Unicode字符之间可 ...
 - sql server C#操作。原文在收藏页面
			
C#操作SQL Server数据库 1.概述 2.连接字符串的写法 3.SqlConnection对象 4.SqlCommand对象 5.SqlDataReader对象 6.DataSet对象 7 ...
 - scala 语言特性
			
Scala 语言特性 Unit 表示无值, 等价于java, C++中的void Null 表示空值或空引用 Nothing 所有其他类型的子类型, 表示没有值 Any 所有类型的超类, 任何实例都属 ...
 - Javascript观察者模式(Object.defineProperty、Reflect和Proxy实现)
			
什么是观察者模式? 答:在数据发生改变时,对应的处理函数自动执行.函数自动观察数据对象,一旦对象有变化,函数就会自动执行. 参考<原生JavaScript实现观察者模式>(https:// ...
 - axios实现类似form传值的格式,以及实现拦截器功能,response拦截实现权限判断
			
import axios from 'axios' import Qs from 'qs' // 超时设置 const service = axios.create({ transformReques ...
 - mybatis基础CURD的学习
			
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "- ...
 - JS ~  Promise 对象
			
Promise 对象用于表示一个异步操作的最终状态(完成或失败),以及该异步操作的结果值. Promise.all(iterable) 这个方法返回一个新的promise对象,该promise对象在i ...
 - tableau创建蜘蛛图
			
tableau官方案例2:创建起点和终点的路径地图 (spider Maps) 源数据样式: 应用:交通图 步骤及注意: 将Line Group (Path ID)维度放入标记卡详细信息 默认的为聚 ...
 - C++ 编程学习(六) 函数
			
零.小知识点 1.函数返回类型可以是除数组外的自定义类型 一.传值调用 向函数传递参数的传值调用方法,把参数的实际值复制给函数的形式参数.在这种情况下,修改函数内的形式参数不会影响实际参数. 默认情况 ...