链接:

https://codeforces.com/contest/1209/problem/C

题意:

You are given a sequence of n digits d1d2…dn. You need to paint all the digits in two colors so that:

each digit is painted either in the color 1 or in the color 2;

if you write in a row from left to right all the digits painted in the color 1, and then after them all the digits painted in the color 2, then the resulting sequence of n digits will be non-decreasing (that is, each next digit will be greater than or equal to the previous digit).

For example, for the sequence d=914 the only valid coloring is 211 (paint in the color 1 two last digits, paint in the color 2 the first digit). But 122 is not a valid coloring (9 concatenated with 14 is not a non-decreasing sequence).

It is allowed that either of the two colors is not used at all. Digits painted in the same color are not required to have consecutive positions.

Find any of the valid ways to paint the given sequence of digits or determine that it is impossible to do.

思路:

枚举x, 比x小的为1,比x大的为2, 同时对x分类, 考虑将右边第一位比x小的右边的x放到1,其余的放到2.

检查一下.

代码:

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5+10; char s[MAXN];
int Col[MAXN];
int n; bool Check()
{
int mmin = 0;
for (int i = 1;i <= n;i++)
{
if (Col[i] == 2)
continue;
if (s[i] < mmin)
return false;
mmin = s[i];
}
mmin = 0;
for (int i = 1;i <= n;i++)
{
if (Col[i] == 1)
continue;
if (s[i] < mmin)
return false;
mmin = s[i];
}
return true;
} int main()
{
int t;
scanf("%d", &t);
while (t--)
{
set<int> St;
scanf("%d", &n);
scanf("%s", s+1);
bool ok = false;
for (int i = 0;i <= 9;i++)
{
for (int j = 1;j <= n;j++)
{
if (s[j]-'0' < i)
Col[j] = 1;
else if (s[j]-'0' > i)
Col[j] = 2;
}
bool flag = true;
for (int j = n;j >= 1;j--)
{
if (s[j]-'0' < i)
flag = false;
if (s[j]-'0' != i)
continue;
if (!flag)
Col[j] = 2;
else
Col[j] = 1;
}
if (Check())
{
ok = true;
break;
}
}
if (!ok)
puts("-");
else
{
for (int i = 1;i <= n;i++)
printf("%d", Col[i]);
printf("\n");
}
} return 0;
}

Codeforces Round #584 C. Paint the Digits的更多相关文章

  1. Codeforces Round #584 A. Paint the Numbers

    链接: https://codeforces.com/contest/1209/problem/A 题意: You are given a sequence of integers a1,a2,-,a ...

  2. Codeforces Round #584

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

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

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

  4. Codeforces Round #584 E2. Rotate Columns (hard version)

    链接: https://codeforces.com/contest/1209/problem/E2 题意: This is a harder version of the problem. The ...

  5. Codeforces Round #584 D. Cow and Snacks

    链接: https://codeforces.com/contest/1209/problem/D 题意: The legendary Farmer John is throwing a huge p ...

  6. Codeforces Round #584 B. Koala and Lights

    链接: https://codeforces.com/contest/1209/problem/B 题意: It is a holiday season, and Koala is decoratin ...

  7. 【Educational Codeforces Round 36 C】 Permute Digits

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] //从大到小枚举第i(1..len1)位 //剩余的数字从小到大排序. //看看组成的数字是不是小于等于b //如果是的话. //说 ...

  8. Codeforces Round 584 题解

    -- A,B 先秒切,C 是个毒瘤细节题,浪费了很多时间后终于过了. D 本来是个 sb 题,然而还是想了很久,不过幸好没什么大事. E1,看了一会就会了,然而被细节坑死,好久才过. 感觉 E2 很可 ...

  9. Codeforces Round #584 (Div. 1 + Div. 2)

    Contest Page A sol 每次选最小的,然后把它的所有倍数都删掉. #include<bits/stdc++.h> using namespace std; int read( ...

随机推荐

  1. [转帖]Docker中的时区问题处理

    Docker中的时区问题处理 这两天在打docker的时候,发现自己的容器启动之后,里面date -R的输出时区是UTC,总是和北京时间差了8个小时. 作者:云平台运维开发来源:今日头条|2019-0 ...

  2. Java操作word转pdf

    如果转换后出现乱码,是doc格式的文档的话请转换为docx!!! 下载相关jar包和一个授权到2099年的凭证文件. 链接: https://pan.baidu.com/s/1xudkKqR1-TLL ...

  3. C++ 日志库 boost::log 以及 glog 的对比

    日志能方便地诊断程序原因.统计程序运行数据,是大型软件系统必不可少的组件之一.本文将从设计上和功能上对比 C++ 语言常见的两款日志库: boost::log 和 google-glog . 设计 b ...

  4. 20191011-构建我们公司自己的自动化接口测试框架-Action的request方法封装

    Action模块 封装接口request方法,根据传入的参数调用不同的请求方法,因为项目特色,我们公司的接口都是get和post方法,所以仅仅封装了get和post方法: import request ...

  5. IntelliJ Idea基于Maven创建SpringMVC程序

    1. 创建Maven工程 网上很多资料,不再详细介绍,请参看IntelliJ IDEA 创建 hello world Java web Maven项目从头到尾都有图有真相2017版本 有关settin ...

  6. asp.net core-2.在vs2017中创建asp.net core应用程序

    今天我们用vs2017创建一个asp.net core 的应用程序,打开vs2017 点击:文件—>项目,选择asp.net core web 应用程序 点击确定 红框内就昨天用控制台去创建的应 ...

  7. 前端 aes 加密

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  8. CTS & APIO 2019 游记

    写在前面 算是省选后的第一轮大考. 去年因为某些原因并没有参加 CTSC 以及 APIO,还是有些遗憾,所以希望今年能有所收获. 也希望今年的 CTS 能延续去年的出题风格,这样我还能苟一两个题. 然 ...

  9. 【原创】大叔经验分享(84)spark sql中设置hive.exec.max.dynamic.partitions无效

    spark 2.4 spark sql中执行 set hive.exec.max.dynamic.partitions=10000; 后再执行sql依然会报错: org.apache.hadoop.h ...

  10. puml 用于代码注释

    notebook 笔记本 @startuml rectangle sql_decode.py{ object SQLDataset object Name SQLDataset : meta = &q ...