链接:

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. [转帖]微软宣布即将开始大规模推送Windows 10 V1903重大版本更新

    微软宣布即将开始大规模推送Windows 10 V1903重大版本更新 https://www.cnbeta.com/articles/tech/894303.htm 微软要批量更新 1903了 bu ...

  2. linux网卡出现问题:Job for network.service failed because the control process exited with error code问题

    [转自]:https://blog.csdn.net/dongfei2033/article/details/81124465 今天在centOS 7下更改完静态ip后发现network服务重启不了, ...

  3. Oracle日常

    Xmltype select extractvalue(value(x), '//utext') value from table(XMLSEQUENCE(extract(v_xmlContent, ...

  4. Python 解LeetCode:744. Find Smallest Letter Greater Than Target

    思路:二分法,时间复杂度o(logn) class Solution(object): def nextGreatestLetter(self, letters, target): "&qu ...

  5. java--demo之猜拳游戏

    版本1:人机大战  基础随机出    用户键盘录入 package com.hainiu.demo; import java.util.Scanner; /* * 人机大战石头剪刀布 */ publi ...

  6. IBM Security AppScan Standard使用方法

    一.常规配置Appscan (安全自动化测试工具) Appscan是web应用程序渗透测试舞台上使用最广泛的工具之一.它是一个桌面应用程序,它有助于专业安全人员进行Web应用程序自动化脆弱性评估.本文 ...

  7. asp.net core-12.dotnet watch run 和attach到进程调试

    1.打开visual studio code 创建一个项目 打开终端 输出:  dotnet new web --name hellocore 2.用visual studio code打开项目文件夹 ...

  8. react以组件为中心的代码分割和懒加载

    背景 随着项目越来越复杂,功能够越来越多,JS单个文件就会比较臃肿,js代码拆分显得必不可少. Js文件拆分主要分为按照路由进行js拆分.按照组件进行js拆分. 按照路由拆分:因为本项目请求路径得原因 ...

  9. delete删除数据造成归档日志增加,操作系统空间不足导致数据库hang住

    业务需求,对日志表历史数据进行清理.历史表均很大,使用delete 操作删除90天前的数据. 第一部分:快速删除数据 SQL> alter table CC.F_LOG parallel ; S ...

  10. java实现当前时间往前推N小时

    import java.text.SimpleDateFormat;import java.util.Calendar;import java.util.Date; /** * @author sha ...