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 ...
随机推荐
- dropna fillna
# NaN 浮点类型 np.nan+1 =>nan Python type(None) // NoneType类型 不能参与运算 import pandas as pd from pand ...
- LeetCode练题——70. Climbing Stairs
1.题目 70. Climbing Stairs——Easy You are climbing a stair case. It takes n steps to reach to the top. ...
- 使用UUID防止文件重名
在原文件名的基础上加 UUID.randomUUID().toString()
- POJ-2891 Strange Way to Express Integers(拓展中国剩余定理)
放一个写的不错的博客:https://www.cnblogs.com/zwfymqz/p/8425731.html POJ好像不能用__int128. #include <iostream> ...
- 新建文件的UID和GID
默认情况下:新建文件的用户ID为操作当前文件进程的有效用户ID(参考以前文章),新建文件的组ID为操作当前文件的进程的有效组ID 特殊情况:当当前新建文件的目录的SET-GID位被设置时,那么新建文件 ...
- 【SSM 下载】下载文件
111111111 /** * 导出客户数据 */ @RequestMapping("exportCustomer") public ResponseEntity<Objec ...
- 【PAT甲级】1053 Path of Equal Weight (30 分)(DFS)
题意: 输入三个正整数N,M,S(N<=100,M<N,S<=2^30)分别代表数的结点个数,非叶子结点个数和需要查询的值,接下来输入N个正整数(<1000)代表每个结点的权重 ...
- case语句!
1.case 语句概述(1)case 语句的作用使用 case 语句改写 if 多分支可以使脚本结构更加清晰.层次分明.针对变量的不同取值,执行不同的命令序列.2.case 语句的结构:case 变量 ...
- Linux查看当前系统32位还是64位
getconf LONG_BIT 此方法会直接返回32或64
- PXE无人值守实现批量化自动安装Linux系统
设想一个场景:假如让你给1000台服务器装系统,你会怎么做?跑去每一台服务器给它安装系统吗?显然不会.. 一.概括 通过网络引导系统的做法可以不必从硬盘.软盘或CD-ROM硬盘,而是完全通过网络来引导 ...