链接:

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. [转帖]超详细的PostgreSQL体系结构总结,值得收藏

    超详细的PostgreSQL体系结构总结,值得收藏 https://www.toutiao.com/i6715390855772897800/ 原创 波波说运维 2019-07-26 00:03:00 ...

  2. insert 一条数据 然后拿出这条数据在数据库中生成的ID

    [insert 一条数据 然后拿出这条数据在数据库中生成的ID] <insert id="insert" parameterType="management&quo ...

  3. 人机交互技术 Week 1_人机交互概述

    HCI Week 1_Introduction 18-19学年春夏学期选修了计院万华根老师的人机交互技术课程,老师由于知识产权相关原因不能提供课件,故尽可能对课程内容做详尽的课堂笔记以供复习,如有不妥 ...

  4. dict字典

    dict字典 字典的概述 • 概述:使⽤键-值(key-value)⽅式存储. • key的特点: • 1.字典中的key必须是唯⼀的 • 2.key值必须是不可变的数据类型:字符串.元组.Numbe ...

  5. C++ 中不能声明为虚函数的函数有哪些?

    目录 普通函数 构造函数 内联成员函数 静态成员函数 友元函数 普通函数 普通函数(非成员函数)只能被overload,不能被override,而且编译器会在编译时绑定函数. 多态的运行期行为体现在虚 ...

  6. 『Python基础练习题』day02

    1.判断下列逻辑语句的True, False 1) 1 > 1 or 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6 2) ...

  7. STM32之ADC实例(基于DMA方式)

    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/zouleideboke/article/details/75112224 ADC简介: ADC(An ...

  8. 解决 org.apache.ibatis.binding.BindingException: Invalid bound statement (not found) 以及MyBatis批量加载xml映射文件的方式

    错误 org.apache.ibatis.binding.BindingException: Invalid bound statement (not found) 的出现,意味着项目需要xml文件来 ...

  9. ASM实例修改SYS密码

    修改ASM实例中SYS用户密码 How To Change ASM SYS PASSWORD ? (文档 ID 452076.1) Oracle Database - Enterprise Editi ...

  10. 入手线段树 hdu1754

    今天学习了线段树的三个基本操作 建树 更新 查找 先理解下什么是线段树就这个题目而言 如果我们用普通的数组去存放 然后依次遍历访问的话 时间太多了线段树利用了二分的思想 把数据以段的形式进行储存 这样 ...