A. Treasure

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/494/problem/A

Description

Malek has recently found a treasure map. While he was looking for a treasure he found a locked door. There was a string s written on the door consisting of characters '(', ')' and '#'. Below there was a manual on how to open the door. After spending a long time Malek managed to decode the manual and found out that the goal is to replace each '#' with one or more ')' characters so that the final string becomes beautiful.

Below there was also written that a string is called beautiful if for each i (1 ≤ i ≤ |s|) there are no more ')' characters than '(' characters among the first i characters of s and also the total number of '(' characters is equal to the total number of ')' characters.

Help Malek open the door by telling him for each '#' character how many ')' characters he must replace it with.

Input

The first line of the input contains a string s (1 ≤ |s| ≤ 105). Each character of this string is one of the characters '(', ')' or '#'. It is guaranteed that s contains at least one '#' character.

Output

If there is no way of replacing '#' characters which leads to a beautiful string print  - 1. Otherwise for each character '#' print a separate line containing a positive integer, the number of ')' characters this character must be replaced with.

Sample Input

(((#)((#)

Sample Output

1
2

HINT

题意

给你一个序列,其中#可以被替换成1个或多个)符号

你需要使得这个序列beautiful

beautiful的定义是,对于每一个i,使得(的个数大于或等于),并且最后(的个数和)的个数相同

题解:

简单分析一下我就可以贪心的去搞一搞

前面的#我们都只替换一个,然后最后的#替换剩下的

然后我们再扫一遍进行check就好了

代码

#include<iostream>
#include<stdio.h>
#include<vector>
using namespace std; string s;
vector<int> ans;
int main()
{
cin>>s;
int sum = ;
int flag = ;
for(int i=;i<s.size();i++)
{
if(s[i]=='(')sum--;
else if(s[i]==')')sum++;
else
{ans.push_back(i);flag++;}
if(sum+flag>)return puts("-1");
}
int k = ans.size();
if(k+sum>)return puts("-1");
else if(k==&&sum!=)return puts("-1");
else
{
int Ans = ;
for(int i=;i<s.size();i++)
{
if(s[i]=='(')Ans--;
else if(s[i]==')')Ans++;
else if(i==ans[ans.size()-])Ans+=-(sum+k-);
else Ans++;
if(Ans>)return puts("-1");
}
for(int i=;i<k;i++)
{
if(i==k-)
printf("%d\n",-(sum+k-));
else
printf("1\n");
}
}
}

Codeforces Round #282 (Div. 1) A. Treasure 水题的更多相关文章

  1. Codeforces Round #185 (Div. 2) B. Archer 水题

    B. Archer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/312/problem/B D ...

  2. Codeforces Round #360 (Div. 2) A. Opponents 水题

    A. Opponents 题目连接: http://www.codeforces.com/contest/688/problem/A Description Arya has n opponents ...

  3. Codeforces Round #190 (Div. 2) 水果俩水题

    后天考试,今天做题,我真佩服自己... 这次又只A俩水题... orz各路神犇... 话说这次模拟题挺多... 半个多小时把前面俩水题做完,然后卡C,和往常一样,题目看懂做不出来... A: 算是模拟 ...

  4. Codeforces Round #256 (Div. 2/A)/Codeforces448A_Rewards(水题)解题报告

    对于这道水题本人觉得应该应用贪心算法来解这道题: 下面就贴出本人的代码吧: #include<cstdio> #include<iostream> using namespac ...

  5. Codeforces Round #340 (Div. 2) B. Chocolate 水题

    B. Chocolate 题目连接: http://www.codeforces.com/contest/617/problem/D Descriptionww.co Bob loves everyt ...

  6. Codeforces Round #340 (Div. 2) A. Elephant 水题

    A. Elephant 题目连接: http://www.codeforces.com/contest/617/problem/A Descriptionww.co An elephant decid ...

  7. Codeforces Round #340 (Div. 2) D. Polyline 水题

    D. Polyline 题目连接: http://www.codeforces.com/contest/617/problem/D Descriptionww.co There are three p ...

  8. Codeforces Round #338 (Div. 2) A. Bulbs 水题

    A. Bulbs 题目连接: http://www.codeforces.com/contest/615/problem/A Description Vasya wants to turn on Ch ...

  9. Codeforces Round #327 (Div. 2) B. Rebranding 水题

    B. Rebranding Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/problem ...

随机推荐

  1. 30道Linux面试题

    1.linux如何挂在windows下的共享目录 mount.cifs //192.168.1.3/server /mnt/server -o user=administrator,pass=1234 ...

  2. 【转】使用autolayout常见错误

    原文网址:http://www.cnblogs.com/xiaokanfengyu/p/4175091.html 使用autolayout常见错误 1:The view hierarchy is no ...

  3. [shell]通过ping检测整个网段IP的网络状态脚本

    要实现Ping一个网段的所有IP,并检测网络连接状态是否正常,很多方法都可以实现,下面简单介绍两种,如下:脚本1#!/bin/sh# Ping网段所有IP# 2012/02/05ip=1 #通过修改初 ...

  4. [Papers]NSE, $\p_3u$, Lebesgue space [Cao, DCDSA, 2010]

    $$\bex \p_3\bbu\in L^p(0,T;L^q(\bbR^3)),\quad \frac{2}{p}+\frac{3}{q}=2,\quad \frac{27}{16}\leq q\le ...

  5. HDU 5750 Dertouzos 简单数学

    感悟:这又是zimpha巨出的一场题,然后04成功fst(也就是这题) 实际上还是too young,要努力增加姿势, 分析:直接枚举这些数不好枚举,换一个角度,枚举x*d,也就是d的另一个乘数是多少 ...

  6. 取requests返回字典值用json()

    python模块requests返回值用json()["h"][key]可以取出下面的value

  7. BootStrap入门教程 (四) :JQuery类库插件(模态窗口,滚动监控,标签效果,提示效果,“泡芙”效果,警告区域,折叠效果,旋转木马,输入提示)

    上讲回顾:Bootstrap组件丰富同时具有良好可扩展性,能够很好地应用在生产环境.这些组件包括按钮(Button),导航(Navigation),缩略图( thumbnails),提醒(Alert) ...

  8. [算法] 选择排序 Selection sort

    选择排序(Selection sort)是一种简单直观的排序算法.它的工作原理如下.首先在未排序序列中找到最小(大)元素,存放到排序序列的起始位置,然后,再从剩余未排序元素中继续寻找最小(大)元素,然 ...

  9. CentOS6 root 用户 vi/vim 无法开启高亮

    编辑 /etc/profile.d/vim.sh if [ -n "$BASH_VERSION" -o -n "$KSH_VERSION" -o -n &quo ...

  10. iOS开发中使用Bmob RESTful API

    简介 尽管Bmob已经提供了一套SDK供开发者使用,但有时候开发者可能希望能直接与Bmob后台进行直接交互,以达到某些特别的需求(直接操作_User表.同步网络请求等).而RESTful API可以使 ...