Codeforces Round #459 (Div. 2) C. The Monster(括号,问号变换,思维题,枚举题)

智能制造之物料详解 制造业业务系统中的物料流转贯穿需求、采购、生产到交付全流程,各系统协同实现精准追踪。需求阶段由CRM/ERP/PLM生成物料计划;采购入库阶段SCM/WMS/QMS完成采购质检;生产阶段MES/APS协调领料加工;成品交付阶段WMS/SCM处理出库物流。整个流程以BOM为蓝图,ERP为调度中心,通过数据联动实现物料状态、位置和数量的全链路可追溯。 阅读详情

C. The Monster
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

As Will is stuck in the Upside Down, he can still communicate with his mom, Joyce, through the Christmas lights (he can turn them on and off with his mind). He can't directly tell his mom where he is, because the monster that took him to the Upside Down will know and relocate him.

Thus, he came up with a puzzle to tell his mom his coordinates. His coordinates are the answer to the following problem.

A string consisting only of parentheses ('(' and ')') is called a bracket sequence. Some bracket sequence are called correct bracket sequences. More formally:

  • Empty string is a correct bracket sequence.
  • if s is a correct bracket sequence, then (s) is also a correct bracket sequence.
  • if s and t are correct bracket sequences, then st (concatenation of s and t) is also a correct bracket sequence.

A string consisting of parentheses and question marks ('?') is called pretty if and only if there's a way to replace each question mark with either '(' or ')' such that the resulting string is a non-empty correct bracket sequence.

Will gave his mom a string s consisting of parentheses and question marks (using Morse code through the lights) and his coordinates are the number of pairs of integers (l, r) such that 1 ≤ l ≤ r ≤ |s| and the string slsl + 1... sr is pretty, where si is i-th character of s.

Joyce doesn't know anything about bracket sequences, so she asked for your help.

Input

The first and only line of input contains string s, consisting only of characters '(', ')' and '?' (2 ≤ |s| ≤ 5000).

Output

Print the answer to Will's puzzle in the first and only line of output.

Examples
input
((?))
output
4
input
??()??
output
7
Note

For the first sample testcase, the pretty substrings of s are:

  1. "(?" which can be transformed to "()".
  2. "?)" which can be transformed to "()".
  3. "((?)" which can be transformed to "(())".
  4. "(?))" which can be transformed to "(())".

For the second sample testcase, the pretty substrings of s are:

  1. "??" which can be transformed to "()".
  2. "()".
  3. "??()" which can be transformed to "()()".
  4. "?()?" which can be transformed to "(())".
  5. "??" which can be transformed to "()".
  6. "()??" which can be transformed to "()()".
  7. "??()??" which can be transformed to "()()()".

题意: 给出字符串,有括号 (),问号 ?,三种字符,问号可以变换为括号,看看能有多少个正确完美的子字符串,正确完美子字符串样式可以重复计算,但同一位置的子串只能算一次;

思路:可以看做枚举每一个区间,看当前区间的字符串,能不能组成完美字符串;也可以看做是包含当前字符的完美子串有多少个;

先把枚举到的问号?字符,都变为右括号,定义 top,num,num表示当前问号 '?' 变为右括号 ')' 的个数;当遇到 '(',top ++;当遇到 ')',top --,当遇到问号的话,先变为 右括号 ')',top--,num++;

代码:

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;

// 可以说是包含当前这个字符的有多少个正确的子串,
//也可以说是枚举每一个区间,看当前区间,能否组成正确的子串,统计的子串样式可以重复; 
char str[5050]; 
int main()
{
	int i,j;
	while( ~scanf( "%s",str ) )
	{
		int l = strlen(str);
		int sum = 0;
		for(i = 0; i < l; i ++)  // 枚举当前字符;也可以说是枚举每一个区间; 
		{
			int top = 0,num = 0;   
			for(j = i; j < l; j ++) // 看包含这个字符的有多少个子串 
			{
				if(str[j] == '(')  top ++;
				else if(str[j] == ')') top --;
				else if(str[j] == '?')  num ++,top --;
				if(top<0&&!num) break;
				if(top<0&&num) top += 2,num --;
				if(!top) sum ++;
			}
		} 
		printf("%d\n",sum);
	}
	return 0;
} 

Amazon Skills:51个AI技能赋能亚马逊运营,从选品到广告全链路分析 在电商运营领域,数据分析和自动化工具正成为提升效率的关键。其核心原理在于将专业经验转化为结构化指令,使AI能够执行标准化流程。这种技术价值体现在降低专业门槛、提升决策效率,尤其适用于亚马逊这类数据驱动的电商平台。通过将选品、关键词研究、FBA费用计算、PPC广告优化等运营框架编码为可执行指令,AI助手能够模拟专家思维进行市场分析。Amazon Skills项目正是这一理念的实践,它提供51个覆盖运营全链路的技能模块,让卖家在自然对话环境中获得专业分析支持,实现从市场研究到利润核算的自动化工作流。 阅读详情

相关推荐

配电网可靠性评估(一)—最小路法和非序贯蒙特卡洛模拟法的matlab实现

电力系统的可靠性研究是相关领域的热点问题。根据研究对象的不同,又可分为发电系统的可靠性,输电系统的可靠性和配电系统的可靠性。配电网在电力系统中处于最末端的位置,直接和用户相连,一旦出现故障情况,就会在用户侧表现为停电事故。因此对配电网的可靠性评估有着重大意义。......

配电网和matlab的博客 1万+

C. The Monster 括号匹配

The Monster 题目大意: 给出一个串,只包含 ( ? ) 三种符号,求出有多少个子串是完美匹配的. 比如 ( ) ? ) => ( ) ( ) 完美匹配 ( ( ) ? => ( ( ) )完美匹配 ? ? ? ? => ( ) ( ) => ( ( ) ) 算一种子串 length 分析: 这个长度和时间限制比较诡异,想不到比较好的方法,猜想

Joovo的博客 474

TwinCAT3与Matlab Simulink集成开发:如何快速生成和调试TcCOM模块

本文详细介绍了如何将TwinCAT3与Matlab Simulink进行深度集成,实现从控制算法模型到实时TcCOM模块的高效开发。通过环境搭建、模型配置、代码生成、系统集成与调试的完整流程,工程师可以快速将Simulink算法部署到倍福实时控制平台,大幅缩短开发周期并提升可靠性。

ik67890123的博客 227

Codeforces Round #459 (Div. 2) C (括号问题)

C. The Monster As Will is stuck in the Upside Down, he can still communicate with his mom, Joyce, through the Christmas lights (he can turn them on and off with his mind). He can't direc...

weixin_30293079的博客 208

LTspice基础教程-024.参数扫描;step指令用法

step指令用于参数扫描,扫描步骤可以是线性的,对数的或列表。 下面介绍几种常用用法: 绘制一简单电阻分压电路,如下: 线性扫描 语法:.step param <Name> <Start Value> <Stop Value> <Increment> 例:.step param Res 20 100 20 意思是R2的阻值从20变化到100,...

gaoyong_wang的博客 3万+

cadence virtuoso 激励信号源

vpulse,vpwl,vsin,vsource信号源介绍

努力学习的IC小白 3万+

Codeforces918 C. The Monster(思维,括号序列)

题意: 给定长度为n的串S,只包含左括号、右括号、问号,三种字符。 其中问号可以替换为任意括号,问有多少个子串是合法括号序列。 数据范围:|S|<=5e3。

zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz 343

【温室气体】GOSAT 数据产品

【温室气体】GOSAT 数据产品

WW、forever的博客 245

【CodeFores-918】 A B C【思维】 D【记忆化搜索】

A - Eleven Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly n characters. Her fr...

lzs_lazy 479

生信技能53 - WisecondorX自动化批量npz转换和reference构建

wiseconrdoX分析CNV适用于CNVseq、NIPT和WGS等项目。

LittleComputerRobot的博客 470

卷积层 (Convolutional Layer) 原理与代码实例讲解

卷积层 (Convolutional Layer) 原理与代码实例讲解 关键词:卷积层,卷积操作,滤波器,特征提取,神经网络 1. 背景介绍 卷积神经网络 (Convolutional N

欢迎来到我的CSDN空间!这里聚焦AI大模型应用实战,分享前沿技术、实战案例与开发经验。 773

【Codeforces Round #459 (Div. 2) C】The Monster

【链接】 我是链接,点我呀:) 【题意】 在这里输入题意 【题解】 左括号看成1 右括号看成-1 设置l,r表示前i个数的和的上下界 遇到 左括号 l和r同时加1 遇到右括号 同时减1 遇到问号 因为问号可以为1或-1所以l减1而r加1 如果在某个时刻r小于0了 就说明再也不能继续了 因为说明左括号和问号比右括号来得少了 如果l<0则把l置为0,因为不允许和出现&l...

98

基于LSTM算法实现交通流量预测(Pytorch版)

本研究采用PyTorch框架,设计并实现了一种基于LSTM(Long Short-Term Memory)网络的交通流量预测模型。针对时序性显著的交通流量数据,模型首先将多节点、多通道的时空信息整合为一维特征输入至多层LSTM单元,利用其捕捉长期依赖及短期波动的能力进行深度学习。全连接层随后调整时间步长以适应预测周期需求。模型结构灵活,能适应不同节点数、输入输出长度及通道配置,实现在给定历史流量数据基础上对未来交通流量的精准预测,为交通管理与规划提供数据驱动支持。

打酱油的葫芦娃 4643

Codeforces Round #459 (Div. 2) C 思维,贪心 D 记忆化dp

Codeforces Round #459 (Div. 2) C. The Monster 题意:定义正确的括号串,是能够全部匹配的左右括号串。 给出一个字符串,有 (、)、 ? 三种字符, ? 可以当作 ( 可 ) 。 问这个字符串有多少个子串是正确的括号串。 tags:好考思维,想不到。。 预处理出每个字符向左向右最多可以匹配到哪里,再 O(n*n) 枚举所有区间,看是否符合条件。 ...

weixin_30807677的博客 145

InTheHand.Net.Personal+BlueTooth4,蓝牙开发

项目中有蓝牙开发的必备dll,现在网上相关的文档博客不少,有的说的多有的说少,但是却很少有这两个dll,分享一下。

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

Codeforces Round #459 (Div. 2) C. The Monster

题目链接 C. The Monster time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output As Will is stuck in the Upside Down, he can still communicat

城南的花 411

全球国家地区城市数据

MySQL全球国家地区城市数据报。。。。。。。。。。。。

Codeforces Round #459 (Div. 2)C The Monster [想法]

Codeforces Round #459 (Div. 2) The Monster [想法]

ACTerminate的博客 372

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

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

Codeforces Round #459 (Div. 2) C-The Monster (贪心)

C. The Monstertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAs Will is stuck in the Upside Down, he can still communicate with his mom, Joyce, th...

Sizaif's 小屋 259

最小二乘法

首先给出公式 最小二乘法的公式 y = a*x+ b; 其中式中N是数据点的个数。注意,以上两式具有相同的分母,∑指逐项加法计算(取和)。∑x指对所有的x值求和,∑y指对所以的y值求和,∑(x^2)指对所有x的平方求和。∑xy指对所有的积xy进行取和计算。应注意,∑xy 与 ∑x*∑y是不相同的(“积的和”与“和的积”是不同的),同样(∑x)^2与∑(x^2)也是不相同的(“和的平方”与...

obsorb_knowledge的博客 9291

E. Bus Video System(找刚开始车上,满足的人数,好题,细节多)

E. Bus Video Systemtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe busses in Berland are equipped with a video surveillance system. The system ...

obsorb_knowledge的博客 4133

Seating Arrangement CSU - 1997 (思维题,是否存在n个数的序列,使得相邻啷个数的差绝对值大于d)

Mr. Teacher老师班上一共有n个同学,编号为1到n。 在上课的时候Mr. Teacher要求同学们从左至右按1, 2, …, n的顺序坐成一排,这样每个同学的位置是固定的,谁没来上课就一目了然了。但是时间长了之后,Mr. Teacher发现坐得离得远的同学往往因为交流很少而逐渐变得生疏了,于是他决定重新安排同学们的座位,并且在新的座位安排中,任意两个相邻的同学的编号之差的绝对值都必须大于d...

obsorb_knowledge的博客 1363

Card Game (First Edition) FZU - 2264 Card Game (Second Edition) FZU - 2265 (数学期望)

Fat brother and Maze are playing a kind of special (hentai) game with some cards. There are N*2 cards in this game for the players to use, this is the card deck. The game goes for N rounds and in each...

obsorb_knowledge的博客 1332

0和5 51Nod - 1433 (为什么整除找出一个最大的整数能整除3或者9,为什么)

小K手中有n张牌,每张牌上有一个一位数的数,这个字数不是0就是5。小K从这些牌在抽出任意张(不能抽0张),排成一行这样就组成了一个数。使得这个数尽可能大,而且可以被90整除。注意:1.这个数没有前导0,2.小K不需要使用所有的牌。Input每个测试数据输入共2行。 第一行给出一个n,表示n张牌。(1&lt;=n&lt;=1000) 第二行给出n个整数a00,a11,a22,…,an−1n−1 (a...

obsorb_knowledge的博客 1287

CodeForces - 892C Pride (n个数,求相邻两个数的最大公约数替换其中一个数,看要操作几次使得n个数全部变成1)

You have an array a with length n, you can perform operations. Each operation is like this: choose two adjacent elements from a, say x and y, and replace one of them with gcd(x, y), where gcd denote

obsorb_knowledge的博客 1156

Super-palindrome HDU - 6264 (改变字符,把每个字符串的奇数子串都变成回文的,一定要善于观察)

题目描述You are given a string that is consisted of lowercase English alphabet.You are supposed to change it into a super-palindrome string in minimum steps.You can change one character in string to anoth...

obsorb_knowledge的博客 831

CodeForces - 879B Table Tennis (不要只顾这个数的一边,这个数的前面和后面都的顾)

n people are standing in a line to play table tennis. At first, the first two players in the line play a game. Then the loser goes to the end of the line, and the winner plays with the next person fro

obsorb_knowledge的博客 773
上一篇: Codeforces Round #461 (Div. 2) A. Cloning Toys(有坑,要考虑细节)
下一篇: Codeforces Round #459 (Div. 2) D. MADMAX 博弈和记忆化搜索(同时照顾两个起点的记忆化搜索)
obsorb_knowledge
博客等级 码龄9年 38粉丝 213原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值