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启动报错-java.net.BindException: Address already in use: bind
启动IDEA报错日志如下: Internal error. Please refer to http://jb.gg/ide/critical-startup-errors java.net.Bind ...
- c#本地缓存当数据库表更改时,缓存失效。
web.config <?xml version="1.0" encoding="utf-8"?> <!-- 有关如何配置 ASP.NET 应 ...
- 安卓开发:初步了解布局文件layout
了解完项目的目录结构,主要文件的作用之后. 了解完各常量文件的定义和使用之后,接下来的重头戏肯定是布局文件layout. 果然,网上关于“安卓布局文件layout”的各种介绍.解析.深入分析,等等资料 ...
- 记springboot 实体类String转Date类型的坑
前端传入一个String的时间字符串如:2019-07-18 23:59:59 后端实体类要在头顶加注解: @DateTimeFormat(pattern = "yyyy-MM-dd HH: ...
- twisted task.cpperator
twisted task.cpperator 1. twisted task.cpperator 1.1. 简介-cooperator 官方文档: https://twistedmat ...
- history路由
class HistoryRouter{ constructor(){ //用于存储不同path值对应的回调函数 this.routers = {}; this.listenPopState(); t ...
- RTT之时钟管理
时钟节拍 :等于 1/T_TICK_PER_SECOND 秒,用 SysTick_Handler实现,在每次加1时都会检查当前线程的时间片是否用完,以及是否有定时器超时.定时值应该为该值的整数倍.非整 ...
- jsp分割字符串并遍历
1.先引入JSTL库 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> ...
- python 之并发编程更新版进程池与进程池比较与回调函数
一.更新版进程池与进程池比较 from concurrent.futures import ProcessPoolExecutor, ThreadPoolExecutor import os, tim ...
- hyfhaha大事记——luogu
成就墙 AK CSP-J 初赛 AK CSP-J 复赛 CSP- J 一等奖 CSP-S 一等奖 大事记 2017-09-20 13:54 注册洛谷账号 之后洛谷一直处于沉沦状态 2018 2018- ...