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, ...
随机推荐
- [转]彻底解决deepin linux的无线网络问题
链接地址:https://bbs.deepin.org/forum.php?mod=viewthread&tid=153154
- [LeetCode] 265. Paint House II 粉刷房子
There are a row of n houses, each house can be painted with one of the k colors. The cost of paintin ...
- zabbix详解
官网地址 https://www.zabbix.com/documentation/3.0/manual/config/items/itemtypes/zabbix_agent 使用率
- AutoResetEvent 学生考试,老师阅卷,学生等待考试结果
class Program { static void Main(string[] args) { )); t.Start(); Console.WriteLine("老师等待提交试卷&qu ...
- js 打印条形码
相应的文件大家去github上下载吧 https://github.com/lindell/JsBarcode <!DOCTYPE html> <html> <head& ...
- Oracle Spatial分区应用研究之二:按县分区与按省分区对比测试报告
1.实验目的 在上一轮的实验中,oracle 11g r2版本下,在87县市实验数据的基础上,比较了分表与分区的效率,得出了分区+全局索引效率较高的结论(见上一篇博客).不过我们尚未比较过不同的分区粒 ...
- BugkuCTF~Misc~WriteUp
1.签到 get flag: Qftm{You should sign in} 2.这是一张单纯的图片 查看图片十六进制 提去特殊字符串进行解码 get flag: key{you are right ...
- while 语句的逻辑
# i =3# username = '大天天'# password = 123# while i > 0:# name = input('请输入你的名字:')# i -= 1# if name ...
- Magic Line(思维+计算几何问题)(2019牛客暑期多校训练营(第三场))
示例: 输入: 140 1-1 01 00 -1 输出:-1 999000000 1 -999000001 题意:给定平面上一系列的点,求一条以(x1,y1),(x2,y2)两点表示的直线将平面分为包 ...
- OpenJDK自动安装脚本 InstallOpenJDK.vbs
Oracle JDK 要收费了,Open JDK没有安装包,只有Zip,写了个安装脚本 InstallOpenJDK.vbs Rem ********************************* ...