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的更多相关文章

  1. Paint the Digits

    C - Paint the Digits 思路:这道题就只需要利用单调栈,将整个数组扫一遍,求得的最后的栈内元素(要求全部小于非栈内元素)的颜色为1,其余为2 那么怎么实现呢?求最后的栈内元素(要求全 ...

  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. ...

  3. Codeforces Round #584

    传送门 A. Paint the Numbers 签到. Code #include <bits/stdc++.h> using namespace std; typedef long l ...

  4. Codeforces Round #584 - Dasha Code Championship - Elimination Round (rated, open for everyone, Div. 1 + Div. 2)

    怎么老是垫底啊. 不高兴. 似乎 A 掉一道题总比别人慢一些. A. Paint the Numbers 贪心,从小到大枚举,如果没有被涂色,就新增一个颜色把自己和倍数都涂上. #include< ...

  5. 详解Paint的setXfermode(Xfermode xfermode)

    一.setXfermode(Xfermode xfermode) Xfermode国外有大神称之为过渡模式,这种翻译比较贴切但恐怕不易理解,大家也可以直接称之为图像混合模式,因为所谓的“过渡”其实就是 ...

  6. android Canvas 和 Paint用法

    自定义view里面的onDraw方法,在这里我们可以绘制各种图形,onDraw里面有两个API我们需要了解清楚他们的用法:Canvas 和 Paint. Canvas翻译成中文就是画布的意思,Canv ...

  7. [LeetCode] Reconstruct Original Digits from English 从英文中重建数字

    Given a non-empty string containing an out-of-order English representation of digits 0-9, output the ...

  8. [LeetCode] Remove K Digits 去掉K位数字

    Given a non-negative integer num represented as a string, remove k digits from the number so that th ...

  9. [LeetCode] Count Numbers with Unique Digits 计算各位不相同的数字个数

    Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...

随机推荐

  1. C语言知识点记录

    1,栈底指针不变,栈顶指针变化. 2,结构化程序包括:顺序,分支,循环. 3,详细设计的任务是为软件结构图的每一个模块确定实现算法和局部数据结构. 4,数据操纵语言:负责数据的操纵,包括查询及增,删, ...

  2. SSIS 从oracle 转数据回MS SQL

    SSIS 从oracle 转数据回MS SQL,转每月的销售记录,大概15000以内,在开发机器上没问题,部署到生产环境出现各种状况“ SSIS 无法从连接伺服器的OLE DB提供者BULK 提取资料 ...

  3. ASP.NET Core搭建多层网站架构【8.2-使用AutoMapper映射实体对象】

    2020/01/29, ASP.NET Core 3.1, VS2019, AutoMapper.Extensions.Microsoft.DependencyInjection 7.0.0 摘要:基 ...

  4. arc066E - Addition and Subtraction Hard

    题目链接 题目大意 给定一个只含加减和数字的表达式,在其中添加括号,使其值最大. 解题思路 显然,只有减号后面的括号会使其中表达式的值取反. 然后只有已经有左括号时才能加入右括号. 所以用\(f_0\ ...

  5. DataFrame loc和iloc的区别

    loc loc是select by label(name) loc函数是选择dataframe中那一行的index == k的 iloc loc是select by position loc函数是选择 ...

  6. 吴裕雄 python 神经网络——TensorFlow 花瓣分类与迁移学习(1)

    import glob import os.path import numpy as np import tensorflow as tf from tensorflow.python.platfor ...

  7. [蓝桥杯2017初赛]k倍区间 前缀和

    题目描述 给定一个长度为N的数列,A1, A2, ... AN. 如果其中一段连续的子序列Ai, Ai+1, ... Aj(i <= j)之和是K的倍数,我们就称这个区间[i, j]是K倍区间. ...

  8. JSON 解析中遇到的坑😭

    最近做加解密遇到一个很“奇葩的问题”,解析服务端加密后的字符串 序列化 时一直报错 "json解析失败:Error Domain=NSCocoaErrorDomain Code=3840 & ...

  9. Linux kali国内源

    命令行:leafpad /etc/apt/sources.list 将原来的内容注释掉,添加以下代码 #中科大 deb http://mirrors.ustc.edu.cn/kali kali-rol ...

  10. Python3.5学习之旅——day5

    模块初识 一.定义 在python中,模块是用来实现某一特定功能的代码集合.其本质上就是以‘.py’结尾的python文件.例如某文件名为test.py,则模块名为test. 二.导入方法 我们在这一 ...