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 ...
随机推荐
- java使用jacob将office文档转换为PDF格式
jacob 包下载地址: http://sourceforge.net/projects/jacob-project/ 下载后,将jacob 与 jacob-1.19-x64.dll放到安装jdk目录 ...
- ViewPort <meta>标记
ViewPort <meta>标记用于指定用户是否可以缩放Web页面,如果可以,那么缩放到的最大和最小缩放比例是什么.使用ViewPort <meta>标记还表示文档针对移动设 ...
- 第六次ScrumMeeting博客
第六次ScrumMeeting博客 本次会议于10月31日(二)22时整在3公寓725房间召开,持续15分钟. 与会人员:刘畅.辛德泰.窦鑫泽.张安澜.赵奕.方科栋. 除了汇报任务外,窦鑫泽同学还就前 ...
- 软工实践-Alpha 冲刺 (5/10)
队名:起床一起肝活队 组长博客:博客链接 作业博客:班级博客本次作业的链接 组员情况 组员1(队长):白晨曦 过去两天完成了哪些任务 描述: 已经解决登录注册等基本功能的界面. 完成了主界面的基本布局 ...
- HDU 5273 Dylans loves sequence 暴力递推
题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5273 bc:http://bestcoder.hdu.edu.cn/contests/con ...
- Java compiler level does not match the version of the installed Java project facet. map解决方法
右键项目"Properties",在弹出的"Properties"窗口左侧,单击"Project Facets",打开"Proje ...
- css声明的优先级
选择器的特殊性 选择器的特殊性由选择器本身的组件确定,特殊性值表述为4个部分,如0,0,0,0,0 一个选择器的具体特殊性如下确定 1.对于选择器给定的ID属性值,加0,1,0,0 2.对于选择器中给 ...
- 结对项目之对PIE的测试程序
项目要求: 构造程序,分别是: 不能触发Fault. 触发Fault,但是不能触发Error. 触发Error,但是不能产生Failure. 结对对象:陈秋月 学号:2013110404 博客地址 ...
- laravel 字段映射问题,表单中提交字段与数据表中字段不一致
在遇到提交表单时,表单中的name属性与数据表中的字段不一致,报错, 解决方法: 参考1:提交表单的时候,表单的name属性和数据表字段名称是一样的,这样有什么不妥么? 你数据库的信息给前端透露得越多 ...
- 更新user的方法
from django.contrib.auth.admin import UserAdmin from django.contrib.auth.forms import UserChangeForm ...