CF1209C Paint the Digits
CF1209C Paint the Digits
题意:给定T组数据,每组数据第一行输入数字串长度,第二行输入数字串,用数字1和2对数字串进行涂色,被1涂色的数字子串和被2涂色的数字子串拼接成新的数字串,要求新的数字串是非递减的。
题解:对原数字串进行排序,然后从后往前和从前往后各涂一次,若涂不完则输出“-”。
#include<iostream>
#include<string.h>
#include<string>
#include<algorithm>
using namespace std;
string a,b;
int vis[];
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
cin>>a;
b=a;
memset(vis,,sizeof(vis));
sort(b.begin(),b.end());
int pos1=n-;
for(int i=n-;i>=;i--)
{
if(b[pos1]==a[i])
{
vis[i]=;
pos1--;
}
}
pos1=pos1+;
int pos2=;
for(int i=;i<n;i++)
{
if(vis[i]==&&a[i]==b[pos2])
{
vis[i]=;
pos2++;
}
}
if(pos1!=pos2)
cout<<'-'<<endl;
else
{
for(int i=;i<n;i++)
cout<<vis[i];
cout<<endl;
}
}
}
CF1209C Paint the Digits的更多相关文章
- Paint the Digits
C - Paint the Digits 思路:这道题就只需要利用单调栈,将整个数组扫一遍,求得的最后的栈内元素(要求全部小于非栈内元素)的颜色为1,其余为2 那么怎么实现呢?求最后的栈内元素(要求全 ...
- Codeforces Round #584 C. Paint the Digits
链接: https://codeforces.com/contest/1209/problem/C 题意: You are given a sequence of n digits d1d2-dn. ...
- Codeforces Round #584
传送门 A. Paint the Numbers 签到. Code #include <bits/stdc++.h> using namespace std; typedef long l ...
- Codeforces Round #584 - Dasha Code Championship - Elimination Round (rated, open for everyone, Div. 1 + Div. 2)
怎么老是垫底啊. 不高兴. 似乎 A 掉一道题总比别人慢一些. A. Paint the Numbers 贪心,从小到大枚举,如果没有被涂色,就新增一个颜色把自己和倍数都涂上. #include< ...
- 详解Paint的setXfermode(Xfermode xfermode)
一.setXfermode(Xfermode xfermode) Xfermode国外有大神称之为过渡模式,这种翻译比较贴切但恐怕不易理解,大家也可以直接称之为图像混合模式,因为所谓的“过渡”其实就是 ...
- android Canvas 和 Paint用法
自定义view里面的onDraw方法,在这里我们可以绘制各种图形,onDraw里面有两个API我们需要了解清楚他们的用法:Canvas 和 Paint. Canvas翻译成中文就是画布的意思,Canv ...
- [LeetCode] Reconstruct Original Digits from English 从英文中重建数字
Given a non-empty string containing an out-of-order English representation of digits 0-9, output the ...
- [LeetCode] Remove K Digits 去掉K位数字
Given a non-negative integer num represented as a string, remove k digits from the number so that th ...
- [LeetCode] Count Numbers with Unique Digits 计算各位不相同的数字个数
Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...
随机推荐
- idea中使用Autowired注入时报红,但是运行不报错
在Preferences中如下设置,即可解除报红错误: 将Autowiring for Bean Class的Severity级别设置为Warning
- 「ZJOI2008」树的统计
树剖模板题啊! 这道题的话,最通(jian)俗(dan)易(cu)懂(bao)的解法应该就是树剖了. 加上线段树维护树上路径的最大权值(\(Max\))和路径和(\(sum\)). 至于\(LCT\) ...
- Python开发:在mac系统中安装pip
pip用来安装python项目的依赖库. 大多数比较新的python版本都自带pip,所以先检查下pip是否有安装. 终端输入:pip --version 如果没有安装pip,那么就用接下来的方式安装 ...
- vue 中 限制 input 输入数字、小数位数等
限制小数位数 <input type="number" @keydown="handleInput2" placeholder="请输入或查看& ...
- eclipse修改工作空间编码格式
一.修改workspace默认编码 eclipse打开window -> 打开preferences 二.修改jsp默认编码 eclipse打开window -> 打开preference ...
- node.js+mysql环境搭建
https://www.jianshu.com/p/9b338095cbe8 node.js+mysql环境搭建 0x01 前言 随着html web技术的发展,和全栈式开发的需求,对于前端人员来讲, ...
- print、println、printf的区别(转载)
printf主要是继承了C语言的printf的一些特性,可以进行格式化输出 print就是一般的标准输出,但是不换行 println和print基本没什么差别,就是最后会换行 System ...
- i.MX RT600之DSP开发环境调试篇
i.MX RT600的Cadence Xtensa HiFi 4 Audio DSP 是一个高度优化过的音频处理器,主频高达600MHz,专门为音频信号的编码.解码以及预处理和后处理模块而设计,功能十 ...
- Dart语言学习(十) Dart流程控制语句
一.条件语句:if.if...elseif.if...elseif...else int score = 95; if (score >=90) { print('优秀'); } else if ...
- 操作系统OS - 反置页表
1. https://blog.csdn.net/wuyuegb2312/article/details/16359821 2. https://www.youtube.com/watch?v=YQ3 ...