CF: Long Number
题目链接
#include<iostream>
#include<string>
using namespace std;
int main()
{
int n;
cin >> n;
string a;
cin >> a;
int f[10];
for(int i = 1; i <= 9; i++)
cin >> f[i];
for(int i = 0; i < n; i++)
{
if(f[a[i] - '0'] > (a[i] - '0'))
{
int j = i;
while(j < n && f[a[j] - '0'] >= (a[j] - '0')) /*这里要注意j的边界问题,至于为什么 >= 见分析1*/
{
a[j] = f[a[j] - '0'] + '0';
j++;
}
break;
}
}
cout << a << endl;
}
分析1:题目原文中有这么一句“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).”, 谷歌翻译后结果为 “您可以执行以下操作不超过一次:在a中选择一个非空的连续子数字段,并用f(x)替换该段中的每个数字x。” 那么为啥写成上面的形式就不难理解了,替换时只能是比它本身大或者和它本身相等,若比它小就不可以了,另外注意判断的顺序是从前往后。
CF: Long Number的更多相关文章
- cf B. Number Busters
http://codeforces.com/contest/382/problem/B 题意:给你Aa,b,w,x,c,然后每经过1秒,c=c-1; 如果b>=x,b=b-x;否则 a=a-1 ...
- CF#235E. Number Challenge
传送门 可以理解为上一道题的扩展板.. 然后我们就可以YY出这样一个式子 ${\sum_{i=1}^a\sum_{j=1}^b\sum_{k=1}^cd(ijk)=\sum_{i=1}^a\sum_{ ...
- CF D. Number Of Permutations 排列
挺水的一道题~ 拿全排列随便乘一下就好了. #include <cstdio> #include <algorithm> #define N 300004 #define ll ...
- 小学四则运算生成器(Java) 刘少允,梁新男
github传送门 项目相关要求 使用 -n 参数控制生成题目的个数.(实现) 使用 -r 参数控制题目中数值(自然数.真分数和真分数分母)的范围.(实现) 生成的题目中计算过程不能产生负数.(实现) ...
- B. Lost Number【CF交互题 暴力】
B. Lost Number[CF交互题 暴力] This is an interactive problem. Remember to flush your output while communi ...
- CF - 392 C. Yet Another Number Sequence (矩阵快速幂)
CF - 392 C. Yet Another Number Sequence 题目传送门 这个题看了十几分钟直接看题解了,然后恍然大悟,发现纸笔难于描述于是乎用Tex把初始矩阵以及转移矩阵都敲了出来 ...
- CF#231DIV2:A Good Number
Let's call a number k-good if it contains all digits not exceeding k (0, ..., k). You've got a numbe ...
- CF 441E Valera and Number
CF 441E Description 一共执行\(k\)次,每次有\(p\%\)把\(x * 2\),有\((100 - p)\%\)把\(x + 1\).问二进制下\(x\)末尾期望\(0\)的个 ...
- CF 724 G. Xor-matic Number of the Graph
G. Xor-matic Number of the Graph 链接 题意: 给定一个无向图,一个interesting的三元环(u,v,s)满足,从u到v的路径上的异或和等于s,三元环的权值为s, ...
随机推荐
- [图片问答]打印html样式有问题
1.加载css样式,参考样例10 http://www.c-lodop.com/demolist/PrintSample10.html2.查看lodop内部解析的html信息,见http://www. ...
- aligin-items与aligin-content的区别
align-items 属性使用于所有的flex容器,它是用来设置每个flex元素在侧轴上的默认对齐方式 aligin-items 与align-content有相同的功能,不过不同点是它是用来让每一 ...
- [LeetCode] 276. Paint Fence 粉刷篱笆
There is a fence with n posts, each post can be painted with one of the k colors. You have to paint ...
- 【Linux】守护进程的定义,作用,创建流程
本文内容: 1.守护进程的定义 2.守护进程的作用 3.守护进程的创建过程 一.守护进程的定义 1.守护进程是脱离于终端并且在后台运行的进程 2.守护进程脱离终端是为了避免在执行过程中的信息在任何终端 ...
- MySql 、Oracle 获取表结构和字段信息
1.MySql获取表结构信息 SELECT TABLE_NAME, TABLE_COMMENT FROM information_schema.`TABLES` WHERE TABLE_SCHEMA ...
- 【LEETCODE】43、1002. Find Common Characters
package y2019.Algorithm.array; import java.util.*; /** * @ProjectName: cutter-point * @Package: y201 ...
- nginx安装错误:No package nginx available
出现错误: 1,备份 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup 2.下载新的CentO ...
- nginx.conf指令详解
#redis.conf # Redis configuration file example. # ./redis-server /path/to/redis.conf ############### ...
- -Dmaven.test.skip=true 和 -DskipTests
-DskipTests,不执行测试用例,但编译测试用例类生成相应的class文件至target/test-classes下. -Dmaven.test.skip=true,不执行测试用例,也不编译测试 ...
- [NOI2008]志愿者招募 (费用流)
大意: $n$天, 第$i$天要$a_i$个志愿者. $m$种志愿者, 每种无限多, 第$i$种工作时间$[s_i,t_i]$花费$c_i$, 求最少花费. 源点$S$连第一天, 容量$INF$ 第$ ...