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 ...
随机推荐
- iOS 开发之 SDWebImage 底层实现原理分析
SDWebImage 是一个比较流行的用于网络图片缓存的第三方类库.这个类库提供了一个支持缓存的图片下载器.为了方便操作者调用,它提供了很多 UI 组件的类别,例如:UIImageView.UIBut ...
- 第八届极客大挑战 Re
0x01.Writeup-RE-CM_2 题目: 解题思路: 1.这个是经过xor的,王老师提示说用xortool,于是放进kali,装好之后执行 xortool CM_2.exe -b, 0.out ...
- Springboot学习:介绍与HelloWorld
1. 什么是 Spring boot Spring Boot来简化Spring应用开发,约定大于配置,去繁从简,just run就能创建一个独立的,产品级别的应用 整个Spring技术栈的一个大整合 ...
- 吴裕雄--天生自然Numpy库学习笔记:NumPy 矩阵库(Matrix)
import numpy.matlib import numpy as np print (np.matlib.empty((2,2))) # 填充为随机数据 numpy.matlib.zeros() ...
- lc 0226
目录 ✅ 232. 用栈实现队列 描述 解答 c py ✅ 496. 下一个更大元素 I 描述 解答 java another java ✅ 232. 用栈实现队列 https://leetcode- ...
- 一大波新款iPhone跟安卓厂商抢夺5G市场
据外媒最新报道称,苹果已经基本完成了今年iPhone的推新阵容,其发布的多款新机中,将涵盖399美元-1149美元的售价区间,特别是5G手机,起步价可能会很亲民,其目的在于进一步占据市场. 今年苹果将 ...
- 启动named服务报错!
安装及配置bind服务程序: yum -y install bind 三个关键文件: 主配置文件(/etc/named.conf) 区域配置文件(/etc/named.rfc1912.zones) 数 ...
- 开关机安全控制!(设置进入bois的密码)
1.调整 BOIS 引导设置(1)将第一引导设备设为当前系统所在硬盘 (2)设置管理员密码 (3)进入bois后如图所示需输入bols密码才能登入
- centos8 docker安装
官方参考地址:https://docs.docker.com/install/linux/docker-ce/centos/ 下载地址: https://download.docker.com/lin ...
- Chrome的一个问题
报错:Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extensi ...