CodeForces 494A Treasure

视觉惯性SLAM系列——ORB-SLAM3的整体介绍及各个线程的功能(五) 跟踪线程(Tracking Thread)作用:负责处理每一帧图像,进行相机位姿的估计和定位。它首先执行与前一帧图像的特征匹配,然后通过仅运动(motion-only)BA(Bundle Adjustment)优化位姿。如果跟踪失败,它会尝试在所有地图中进行重定位。此外,跟踪线程还负责决定何时插入新的关键帧,以及何时将关键帧从局部地图中移除。详细介绍见局部建图线程(Local Mapping Thread)作用:管理局部地图,向活跃地图添加关键帧和点,移除多余的关键帧和点。 阅读详情
A. Treasure
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

If there are several possible answers, you may output any of them.

Sample test(s)
input
(((#)((#)
output
1
2
input
()((#((#(#()
output
2
2
1
input
#
output
-1
input
(#)
output
-1

题目大意:有一个字符串包括字符“(”,“)”
#include <cstdio>
#include <cstring>
const int maxn=100010;
char s[maxn];
int main()
{
    int a=0,b=0,c=0,i;
    scanf("%s",s);
    int len=strlen(s);
	if(s[0]==')'||s[len-1]=='('||s[0]=='#')
    {
        printf("-1\n");
        return 0;
    }
	for(i=len-1;i>=0;i--)
	{
		if(s[i]=='(')
			a++;
		if(s[i]==')')
			b++;
		if(a>b)
		{
			printf("-1\n");
			return 0;
		}
		if(s[i]=='#')break;
	}
	a=0,b=0;
    for(i=0;i<len;i++)
    {
        if(s[i]=='(')//记录“(”的个数
            a++;
        if(s[i]==')')//如果有合法的一对括号,把他们标记为“.”
		{
			if(s[i-1]=='(')
			{
				s[i-1]='.';
				s[i]='.';
				b--;
				a--;
			}
            b++;
		}
        if(s[i]=='#')
		{
			b++;
            c++;
		}
		if(b>a)//判断“#”后面的左右括号数是否相等,左括号多则不合法
		{
			printf("-1\n");
			return 0;
		}
    }
	b-=c;
    if(a-b<c)
    {
        printf("-1\n");
        return 0;
    }
	a=0;
	for(i=0;i<len;i++)
	{
		if(s[i]=='(')
			a++;
		if(s[i]==')')
		{
			b--;
			a--;
		}
		if(s[i]=='#')
		{
			if(c>1)
			{
				printf("1\n");
				a--;
				c--;
			}
			else
			printf("%d\n",a-b);
		}
	}
    return 0;
}

,“#”,遇到#时把它转变成“)”,求每个#转换成几个“)”能使所有左右括号合法。

解题思路:第一个字符不是“(”或者最后一个字符是“(”不合法,“#”后面左括号大于右括号不合法,“#”个数大于“(”个数-“)”个数的差值不合法。如果合法,前面的“#”转换为1个括号,最后的“#”转换为剩下的左括号的个数。

代码如下:

PCL 直通滤波器【2026最新版】 PCL直通滤波器函数详解以及用于多字段滤波、强度滤波、获取某一时间范围内的点等高阶用法案例分享。博客长期更新,本文最近一次更新时间为:2026年3月11日。 阅读详情

相关推荐

太速科技-基于DSP TMS320C6678+FPGA XC7V690T的6U VPX信号处理卡

当多块盘并行工作时,存储阵列读写带宽成指数增长,2块盘则≥4GB/s,4块盘则≥8GB/s,以此类推。存储阵列的存储容量由单盘配置决定,目前单块NVME存储盘存储容量可选择512GB、1TB、2TB、4TB、8TB、16TB。硬盘管理通过文件系统,FPGA的PCIeX4与 6U VPX主板互联,操作系统直接映射管理硬盘,也可以通过前面板QSFP+ 光纤导出给其他服务器设备。本方案优势就是集中的进行采集,存储,计算一体化,降低硬件成本、功耗,减小设备体积、重量。信号处理,无线电通信领域。

Orihard_的博客 678

CodeForces 494A Treasure

原则:任意位置左边的左括号的数量必须小于等于右括号的数量。 先统计一遍左括号的数量和右括号的数量,将除了最后一个#号外的#号全填一个右括号,剩下的在最后一个#号处补齐。 然后扫一遍判断是否满足原则。 #include #include #include #include using namespace std; char s[100100]; int ans[100100]; int

UnknownCUnknown的专栏 554

单相变换器的二次纹波分析

1. 单相PWM整流器的二次纹波产生原因   单相变换器的二次纹波产生的原因是功率含有二次脉动分量。设电网电压 us=Vmsin(wt),电网电流IL=Imsin(wt−θ)I_L=I_msin(wt-\theta)IL​=Im​sin(wt−θ)。其中w是电网电压披绿,θ\thetaθ是电流之后电压相位。保证输入功率和输出功率相等,就要保证两者的直流量和交流量对应相等。   uDu_DuD​为 PWM 整流器直流电容电压平均值,IoI_oIo​ 为负载电流平均值 ,uDC^\widehat {u_{DC}

qq_38847810的博客 4973

Codeforces 494A Treasure (思维 模拟)

Codeforces 494A Treasure (思维 模拟)

Tc的专栏 827

基于STM32的Modbus TCP多主站数据监测

Modbus TCP通信协议在STM32上实现,STM32作为服务器采集内部传感器数据,并通过ADC进行转换,存入寄存器。两个PC机作为客户端访问服务器,服务器通过Socket通信实现监听连接,将数据发送给客户端。

hyp12347的博客 4291

SBP依赖计算中的蝴蝶效应:一个Prefab修改如何触发全量重建?

本文深入探讨了Unity中SBP(Scriptable Build Pipeline)依赖计算的蝴蝶效应,解析了Prefab修改如何触发全量重建的机制。通过分析Asset与Object的层级关系、依赖计算的三种维度及CacheEntry系统,揭示了全量重建的根本原因,并提供了依赖可视化工具开发、优化策略与最佳实践,帮助开发者提升构建效率。

weixin_29015051的博客 444

codeforces 494A Treasure

A. Treasure time limit per test2 seconds memory limit per test256 megabytes Malek has recently found a treasure map. While he was looking for a treasure he found a locked door. There was a string

Tc的专栏 1253

军品研制过程-转阶段

介绍军品转阶段评审

Abel的博客 2万+

Codeforces 494A

#include<iostream> #include<cstdio> #include<string> #include<cstring> #include<string.h> #include<algorithm> #...

chiyimai0460的博客 175

SpringBoot实战教程-springboot概论

Spring Boot 是一个快速开发框架,能够快速的整合第三方框架,简化XML配置,全部采用注解形式,以及自动配置。内置web容器,帮助开发者能够实现快速开发,简化了应用系统的初始搭建以及开发过程。

鸟哥哥的专栏 4155

Codeforces #494 A. Polycarp's Pockets

A. Polycarp's Pockets废话不多说,直接上AC程序!#include&lt;bits/stdc++.h&gt; using namespace std; int n,x; int t[101]; int main(){ scanf("%d",&amp;n); for (int i=1;i&lt;=n;i++){ scanf("%d",&amp;x)...

scy1106的博客 227

2.0 电子凸轮 西门子1500电子凸轮使用研究1

本文研究了S7-1500T电子凸轮同步控制技术,通过仿真实验得出以下结论:1)通过比例系数可调整凸轮曲线形状;2)解除同步需调用从轴其他运动指令;3)详细阐述了凸轮同步的5个实施步骤。重点分析了三种同步类型(主值距离同步、动态参数同步和直接同步)的特点及应用场景,并探讨了缩放系数、偏移量等参数对凸轮曲线的影响。同时介绍了凸轮应用模式及常见异常处理方法,为工程应用提供了重要参考。

qq_34047402的博客 808

【Codeforces 494A】Treasure

【链接】 我是链接,点我呀:) 【题意】 让你把"#"用至少一个右括号代替 使得整个括号序列合法 【题解】 首先我们不要考虑井号 考虑最简单的括号序列 并且把左括号看成1,右括号看成是-1 然后用a[]表示它的一个前缀和(a[0]=0) 这样 这个括号序列合法的充要条件就是 ①a[i]>=0 (1<=i<=len(s)) ②a[len(s)] = 0 这...

113

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

CodeForces 494A Treasure 【greedy】

A. Treasure time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Malek has recently found a treasure map. While

shengweisong 1463

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

Treasure CodeForces - 494A 思路题

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...

Accepted 531

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

CodeForces 494A Treasure(字符串匹配 思维)

http://codeforces.com/problemset/problem/494/A 题意 有一串字符串由 ( ) # 组成 #代表若干个 ) 问#具体为多少时可以使每个( 都对应一个 ) 思路 由于可以有多种方式组合 可以默认前 cnt-1 个 #号 与它前一个 ( 匹配 之后再对最后一个#进行特判(分别判断 ...

weixin_30530523的博客 111

Treasure - CodeForces 494 A 水题

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

提比的强行AC 735

Codeforces 494 A. Treasure && Codeforces Round #282 (Div. 1)

题目链接:http://codeforces.com/problemset/problem/494/A 解题思路:Codeforces官方题解: Consider a string consisting of '(' and ')' characters. Let's build the following sequence from this string: a

piaocoder 761

Treasure CodeForces - 494A(栈模拟)

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...

Never__give__up的博客 335

CodeForces 494A - Treasure(STL初体验)

A. Treasure Malek has recently found a treasure map. While he was looking for a treasure he found a locked door. There was a stringswritten on the door consisting of characters '(',...

weixin_30439031的博客 135

codeforces 494a//Treasure// Codeforces Round #282(Div. 1)

题意:一个'(' , ')' , '#'组成的串,可将'#'换成至少一个')'。问一个换法能使串匹配。 至少换成一个,那么就先都换成一个,记结果为str。最后一个')'的后面没有未匹配的'('时可行。否则输出-1。因为后面不可能再添加')'了。如果str会因为')'匹配不到'('则无解。否则有解,将str中'('的数量-')'的数量加到最后一个串中。 乱码: //#pragma ...

weixin_30375247的博客 117

Codeforces Round #282 (Div. 1) A. Treasure 水题

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 f...

weixin_34290390的博客 144

Codeforces 500C New Year Book Reading

New Year Book Reading Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 500C Description New Year is coming, and Jaehyun

ysCover 937

CodeForces 496B Secret Combination

B. Secret Combination time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You got a box with a combination lock

ysCover 854
上一篇: POJ 2586 Y2K Accounting Bug
下一篇: CodeForces 509B Painting Pebbles
雨狮子
博客等级 码龄12年 24粉丝 185原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值