SGU179 Brackets light
179. Brackets light
memory limit per test: 131072 KB
output: standard
Your task is to find next (in lexicographic order) correct brackets sequence with the same length. You may assume that '(' < ')'.
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; char s[];
int len, cnt;
bool flag = false; void update()
{
for (int i = len; i >= ; i--)
if (s[i] > s[i - ])
{
swap(s[i], s[i - ]);
reverse(s + i + , s + len + );
break;
}
} bool check()
{
cnt = ;
for (int i = ; i <= len; i++)
{
if (s[i] == '(')
cnt++;
else
{
if (cnt == )
return false;
else
cnt--;
}
}
if (cnt)
return false;
return true;
} int main()
{
while (scanf("%s", s + ) != EOF)
{
len = strlen(s + );
flag = false;
for (int i = ; i <= len; i++)
if (s[i] == '(' && s[i + ] != ')')
{
flag = true;
break;
}
if (!flag)
puts("No solution");
else
{
while ()
{
update();
if (check())
break;
}
for (int i = ; i <= len; i++)
printf("%c", s[i]);
printf("\n");
}
} return ;
}
SGU179 Brackets light的更多相关文章
- SGU 179 Brackets light(生成字典序的下一个序列)
题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=179 解题报告:输入一个合法的括号串,求出这个括号串的字典序的下一个串.(认为'(' ...
- SGU 179.Brackets light
时间限制:0.25s 空间限制:12M 题意 给定一个合法的仅由'(',')'组成的括号序列,求它的下一个合法排列.假定'('<')'. Solution: ...
- vs code 插件收集
名称 简述 Auto Close Tag 自动闭合HTML标签 Auto Import Typescript自动import提示 Auto Rename Tag 修改HTML标签时,自动修改匹配的标签 ...
- SGU 分类
http://acm.sgu.ru/problemset.php?contest=0&volume=1 101 Domino 欧拉路 102 Coprime 枚举/数学方法 103 Traff ...
- vscode python开发插件推荐
vscode作为一款好用的轻量级代码编辑器,不仅支持代码调试,而且还有丰富的插件库,可以说是免费好用,对于初学者来说用来写写python是再合适不过了.下面就推荐几款个人觉得还不错的插件,希望可以帮助 ...
- 工具 - VS Code
杂项 1. 主题 brackets light pro, One Monokai theme 2. directory tree indent guidelines, directory vertic ...
- 【代码编译器】vscode 配置详细介绍
前言:运行环境.net6.0 C#10 安装.NET Core SDK和运行 官网下载地址:https://www.microsoft.com/net/download/core 安装.Net 4.7 ...
- LED Decorative Light Supplier - LED Environmental Decorative Lighting Application
Creating ambient lighting in the home can bridge the gap between the internal world and the outside ...
- LED Decorative Light Supplier - LED Neon Application: 5 Advantages
In the past 100 years, lighting has gone a long way. LED decorative lighting is now designed to meet ...
随机推荐
- kubernetes nfs-client-provisioner外部存储控制器
介绍: nfs-client-provisione是一个专门用于NFS外部目录挂载的控制器,当多个副本创建时,他们的命名方式如下: pv provisioned as ${namespace}-${p ...
- POJ 3579 Median 二分加判断
Median Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12453 Accepted: 4357 Descripti ...
- Pearson Distance
Pearson Distance: where: 1. is the covariance 2. is the standard deviation of 3. is the standard ...
- 食物链 POJ 1182(种类并查集)
Description 动物王国中有三类动物A,B,C,这三类动物的食物链构成了有趣的环形.A吃B, B吃C,C吃A. 现有N个动物,以1-N编号.每个动物都是A,B,C中的一种,但是我们并不知道它到 ...
- Python Requests库入门——应用实例-百度、360搜索关键词提交
百度的关键词接口: http://www.baidu.com/s?wd=keyword 360的关键词接口: http://www.so.com/s?q=keyword keyword就是需要查找的关 ...
- 第8章 Linux磁盘与文件系统管理
认识EXT2文件系统 文件的系统特性 Linux的正规文件系统为Ext2 文件数据除了文件实际内容外,还包括其他属性(文件权限.文件属性). 文件系统将这两部分数据分别存放在不同的块,权限和属性放在i ...
- JAVA第三次笔记
- 【leetcode】198.HouseRobber
198.HouseRobber You are a professional robber planning to rob houses along a street. Each house has ...
- LR监控apache服务器
开启mod_status模块功能,在LR的controller中找到apache资源图双击并右键添加度量,如下图: 添加apache服务器IP地址.选择系统平台.添加需要监控的计数器即可进行 ...
- php中ob缓存机制
1.ob缓存运行方式 2.注意:在程序中如果开启ob_start(),所有的echo输出都会保存到ob缓存中,可以使用ob系列函数进行操作,如果没有,默认情况下,在程序执行结束,会把缓存中的数据发送给 ...