SSL2770 2017年10月17日提高组 神奇变化
来源:互联网 发布:男士面霜 知乎 编辑:程序博客网 时间:2024/05/29 04:20
2017年10月17日提高组 神奇变化
Description
给定一个有n个数字的序列,记作{an},需要进行k次操作,每次操作找到最小的x使得a(x)=2,a(x+1)=3,如果x为奇数,则令d(x+1)=2,反之令d(x)=3,若没有这样的x则数字不变。
求k此操作之后原数列会变成什么
Input
本题有多组数据。
每组数据第一行是两个正整数n,k分别表示数字个数和操作次数
第二行有n个数字,数字之间没有空格
Output
对每组数据输出一行为最终的数列
分析:据大佬说:很显然的题目,直接O(n)扫一遍就好。。。(tips:不难发现到223或233时会循环。)
代码
#include <cstdio>#include <string>#include <cstring>#define maxn 2000000using namespace std;int n,k;char a[maxn];int main(){ while(~scanf("%d%d",&n,&k)) { int p=0; scanf("%s",a+1); int i=1; while (i<=n&&k>0) { if (a[i]=='2'&&a[i+1]=='3') { int mo=i%2; if (a[i+2]=='3'&&mo==1) break; if (mo==0) { a[i]='3'; i--; k--; continue; } else { a[i+1]='2'; i++; k--; continue; } } i++; } k%=2; if (k==1) a[i+1]='2'; for (int i=1;i<=n;i++) printf("%c",a[i]); printf("\n"); }}
阅读全文
0 0
- SSL2770 2017年10月17日提高组 神奇变化
- 【SSLGZ 2770】2017年10月17日提高组 神奇变化
- 2017年8月17日提高组T1 游戏
- 2017年8月17日提高组T1 游戏
- 2017年8月17日提高组T2 考试
- 2017年8月10日提高组T1 数学
- 2017年8月10日提高组T1 数学
- 2017年8月10日提高组T1 数学
- 2017年10月6日提高组T2 挖矿
- 2017年10月6日提高组T2 挖矿
- 2017年10月7日提高组T1 染色
- SSL2775 2017年10月19日提高组 新壳栈
- 2017年10月23日提高组T3 询问
- 2017年10月28日提高组 Num
- 2017年10月30日提高组T1 数论
- SSL2772 2017年10月17日提高组 被关押的ymw(prim)
- 2017年8月7日提高组T1 呵呵
- 2017年8月7日提高组T1 呵呵
- 统计难题 HDU
- ue4 for循环不能用delay
- 数据结构实验之栈与队列十一:refresh的停车场
- Codeforces Round #202 (Div. 1) B. Apple Tree CF348B
- 面试题
- SSL2770 2017年10月17日提高组 神奇变化
- 机器学习笔记一:K邻近算法心得!
- Linux crontab不会执行
- 3.3
- 1015. Reversible Primes (20)
- python零基础学习2-编辑器选择
- 杨辉三角形
- 第一个java程序
- 冒泡排序