CF #504 div2 A.B.C

本文探讨了三种字符串处理问题:通配符模式匹配、玩具对的选择及括号序列子序列生成。通过具体实例和代码解析,展示了如何解决这些问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A. Single Wildcard Pattern Matching

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given two strings ss and tt. The string ss consists of lowercase Latin letters and at most one wildcard character '*', the string ttconsists only of lowercase Latin letters. The length of the string ss equals nn, the length of the string tt equals mm.

The wildcard character '*' in the string ss (if any) can be replaced with an arbitrary sequence (possibly empty) of lowercase Latin letters. No other character of ss can be replaced with anything. If it is possible to replace a wildcard character '*' in ss to obtain a string tt, then the string tt matches the pattern ss.

For example, if s=s="aba*aba" then the following strings match it "abaaba", "abacaba" and "abazzzaba", but the following strings do not match: "ababa", "abcaaba", "codeforces", "aba1aba", "aba?aba".

If the given string tt matches the given string ss, print "YES", otherwise print "NO".

Input

The first line contains two integers nn and mm (1≤n,m≤2⋅10^5) — the length of the string ss and the length of the string tt, respectively.

The second line contains string ss of length nn, which consists of lowercase Latin letters and at most one wildcard character '*'.

The third line contains string tt of length mm, which consists only of lowercase Latin letters.

Output

Print "YES" (without quotes), if you can obtain the string tt from the string ss. Otherwise print "NO" (without quotes).

Examples

input

6 10
code*s
codeforces

output

YES

input

6 5
vk*cup
vkcup

output

YES

input

1 1
v
k

output

NO

input

9 6
gfgf*gfgf
gfgfgf

output

NO

Note

In the first example a wildcard character '*' can be replaced with a string "force". So the string ss after this replacement is "codeforces" and the answer is "YES".

In the second example a wildcard character '*' can be replaced with an empty string. So the string ss after this replacement is "vkcup" and the answer is "YES".

There is no wildcard character '*' in the third example and the strings "v" and "k" are different so the answer is "NO".

In the fourth example there is no such replacement of a wildcard character '*' that you can obtain the string tt so the answer is "NO".

题目大意:给出2个串,第一个串里可能有*,对比2个串,若相同输出YES否则NO。*比较特殊,可以变成任何的字符串,空格也行。这个变什么由你决定。

思路:样例解释的非常清楚,所以顺着做就行了,没*号直接判断,有*号先顺次判断,然后倒着判断就行了。

代码如下:

#include <iostream>
#include <string>
#include <map>
using namespace std;
int main()
{
	int n,m,i,j;
	while(cin>>n>>m)
	{
		string s,t;
		int flag=0;
		int p=-1;
		cin>>s>>t;		
		for(i=0;i<n;i++)//顺序匹配 
		{
			if(s[i]=='*') {p=i;break;} 
			else{
				if(s[i]!=t[i])
					flag=1;
			}
			if(flag==1) break;//不匹配弹出 
		}		
		for(i=n-1,j=m-1;i>p;i--,j--)//逆序匹配 
		{
			if(s[i]!=t[j]) flag=1;//不匹配			
			if(flag==1) break;
		}		
		if(p==-1)//无星 
		{
			if(n!=m) flag=1;
		}
		else if(n-m>1) flag=1;		
		if(flag==0) cout<<"YES";
		else cout<<"NO";	
		cout<<endl;
	}
	return 0;
}

B. Pair of Toys

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Tanechka is shopping in the toy shop. There are exactly nn toys in the shop for sale, the cost of the ii-th toy is ii burles. She wants to choose two toys in such a way that their total cost is kk burles. How many ways to do that does she have?

Each toy appears in the shop exactly once. Pairs (a,b) and (b,a) are considered equal. Pairs (a,b), where a=b, are not allowed.

Input

The first line of the input contains two integers nn, kk (1≤n,k≤10^14) — the number of toys and the expected total cost of the pair of toys.

Output

Print the number of ways to choose the pair of toys satisfying the condition above. Print 0, if Tanechka can choose no pair of toys in such a way that their total cost is kk burles.

Examples

input

8 5

output

2

input

8 15

output

1

input

7 20

output

0

input

1000000000000 1000000000001

output

500000000000

Note

In the first example Tanechka can choose the pair of toys (1,4) or the pair of toys (2,3).

In the second example Tanechka can choose only the pair of toys (7,87,8).

In the third example choosing any pair of toys will lead to the total cost less than 2020. So the answer is 0.

In the fourth example she can choose the following pairs: (1,1000000000000), (2,999999999999), (3,999999999998)(3,999999999998), ..., (500000000000,500000000001). The number of such pairs is exactly 500000000000.

题目大意:给出2个数n,k。要求在1-n中取2个数ab,使a+b=k,问有多少种取法。(例如 n=8 k=15,则只有一种a=7,b=8(a=8 b=7算一种,且a!=b)。

思路:水题,稍微想一下就行。考虑2种情况,大于k/2和大于k。详情看代码吧。

#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<string>
using namespace std;
int main()
{
	long long int n,k,i,j,s;
	cin>>n>>k;
	if(n<k/2) cout<<"0"<<endl;
	else {
		if(n>=k) n=k-1;
		cout<<n-k/2<<endl; 
	}
	return 0;
}

C. Bracket Subsequence

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

A bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()()" and "(())" are regular (the resulting expressions are: "(1)+(1)" and "((1+1)+1)"), and ")(", "(" and ")" are not.

Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements.

You are given a regular bracket sequence ss and an integer number kk. Your task is to find a regular bracket sequence of length exactly kksuch that it is also a subsequence of ss.

It is guaranteed that such sequence always exists.

Input

The first line contains two integers nn and kk (2≤k≤n≤2⋅10^5, both nn and kk are even) — the length of ss and the length of the sequence you are asked to find.

The second line is a string ss — regular bracket sequence of length nn.

Output

Print a single string — a regular bracket sequence of length exactly kk such that it is also a subsequence of ss.

It is guaranteed that such sequence always exists.

Examples

input

6 4
()(())

output

()()

input

8 8
(()(()))

output

(()(()))

题目大意:给出这个字符串和a,b数字,a是字符串长度,b为所求子串长度。条件:使子串符合运算法则,操作:加1和+。

思路:搞不清楚题意,然后瞎搞了一发,就过了....过了.....

代码如下:

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
char s[200005];
int main()
{
  int k,n,a,b;
  while(~scanf("%d%d",&n,&k))
  {
    a=0,b=0;
    scanf("%s",s);
    int len=strlen(s);
    for(int i=0;i<len;i++)
	{
        if(s[i]=='('&&a<k/2)
	    {
            a++;
            printf("(");
        }
		else if(s[i]==')'&&b<k/2)
		{
           b++;
           printf(")");
        }
    }
    printf("\n");
  }
  return 0;
}

 

<h2 class="level2">一、研究背景与意义</h2> <div class="content"> 复杂肝胆管结石是肝胆外科难治性疾病之一,具有结石分布广泛、胆管狭窄发生率高、肝实质萎缩明显等特点,术后结石残留率(20%-50%)和复发率(23.8%)居高不下,严重影响患者预后<document id="2"></document><document id="8"></document>。精准定位结石、评估胆管狭窄及肝内血管解剖是提高手术疗效的关键,但传统影像学检查(如超声、CT)存在二维图像空间分辨率有限、难以实时动态评估等不足<document id="3"></document>。 </div> <div class="content"> 三维可视化技术通过对肝脏、胆道及血管的数字化重建,可立体显示结石分布、胆管狭窄部位及血管解剖关系,显著降低结石残留率(0% vs 9.5%)和手术时间(218.8min vs 254.7min)<document id="2"></document><document id="4"></document>;术中超声可实时定位深部结石、评估胆管通畅性,弥补术前三维重建静态评估的局限<document id="38"></document>。然而,目前关于两者联合应用的系统性研究较少,其在复杂肝胆管结石中的协同价值尚未明确。本研究旨在探索三维可视化联合术中超声的应用效果,为优化复杂肝胆管结石诊疗策略提供依据。 </div> <h2 class="level2">二、国内外研究现状</h2> <div class="content"> 国外研究表明,三维重建技术可提高肝切除术的精准性,其引导的手术在结石清除率(100% vs 90.5%)和胆管狭窄矫正率(98.2% vs 85.7%)方面优于传统手术<document id="2"></document>。术中超声在实时定位肝内微小结石(<5mm)中表现突出,但其单独应用受限于操作者经验,对复杂胆管解剖的整体评估不足<document id="6"></document>。 </div> <div class="content"> 国内研究中,三维可视化技术已广泛用于肝胆管结石的术前规划,如MI-3DVS软件可实现胆道系统的个体化重建,引导腹腔镜解剖性肝切除的结石清除率达100%<document id="3"></document><document id="4"></document>;术中超声联合胆道镜可提高复杂病例的结石取出率(93.3% vs 78.6%)<document id="8"></document>。但现有研究多聚焦单一技术的应用,对三维可视化与术中超声的联合评估、动态协同机制探讨不足,尤其缺乏对双侧肝胆管结石、合并肝萎缩病例的针对性分析<document id="35"></document><document id="39"></document>。 </div> <h2 class="level2">三、研究目的与内容</h2> <h2 class="level2" style="font-size:16pt">(一)研究目的</h2> <div class="content"> 1. 评估三维可视化联合术中超声在复杂肝胆管结石术前规划、术中定位及术后疗效中的应用价值;<br> 2. 比较联合技术与单一技术(三维可视化或术中超声)在手术指标(出血量、时间)、结石清除率及复发率中的差异;<br> 3. 建立基于联合技术的复杂肝胆管结石个体化诊疗流程。 </div> <h2 class="level2" style="font-size:16pt">(二)研究内容</h2> <div class="content"> 1. 病例选择:回顾性收集2022年1月至2024年1月80例复杂肝胆管结石患者,分为联合组(40例,三维可视化+术中超声)和对照组(40例,单一三维可视化或术中超声),纳入标准:结石分布≥2个肝段、合并胆管狭窄或肝萎缩<document id="24"></document><document id="31"></document>;<br> 2. 技术应用:联合组术前通过三维重建明确手术范围,术中超声实时验证结石清除情况及胆管通畅性;对照组采用单一技术引导手术<document id="4"></document><document id="38"></document>;<br> 3. 疗效评价:比较两组手术时间、术中出血量、结石清除率(术后1周CT/MRCP评估)、术后6个月复发率及并发症(胆瘘、胆管炎)发生率<document id="2"></document><document id="8"></document>。 </div> <h2 class="level2">四、研究方法与技术路线</h2> <h2 class="level2" style="font-size:16pt">(一)研究方法</h2> <div class="content"> 1. 三维重建:采用64排螺旋CT采集数据(层厚0.625mm),通过MI-3DVS软件进行肝脏、胆道、血管分割与重建,测量结石体积、胆管狭窄程度及拟切除肝段体积<document id="4"></document><document id="36"></document>;<br> 2. 术中超声:采用高频探头(5-10MHz)实时探查肝内结石、评估胆管直径及血流情况,重点验证三维重建显示的狭窄部位和血管走形<document id="38"></document><document id="41"></document>;<br> 3. 统计学分析:采用SPSS 26.0,计量资料以(x±s)表示,组间比较用t检验;计数资料以率表示,用χ&sup2;检验,P<0.05为差异有统计学意义。 </div> <h2 class="level2" style="font-size:16pt">(二)技术路线</h2> <div class="content"> 病例筛选&rarr;分组(联合组/对照组)&rarr;联合组:术前三维重建+术中超声引导手术;对照组:单一技术引导手术&rarr;术后1周评估结石清除率&rarr;术后3、6个月随访(复发率、并发症)&rarr;数据统计分析&rarr;结论 </div> <h2 class="level2">五、预期成果与创新点</h2> <h2 class="level2" style="font-size:16pt">(一)预期成果</h2> <div class="content"> 1. 明确三维可视化联合术中超声可提高复杂肝胆管结石的结石清除率(≥95%),降低复发率(<5%);<br> 2. 形成《三维可视化联合术中超声在复杂肝胆管结石中的应用指南》;<br> 3. 发表核心期刊论文2-3篇,申请实用新型专利1项。 </div> <h2 class="level2" style="font-size:16pt">(二)创新点</h2> <div class="content"> 1. 首次系统探讨三维可视化与术中超声的协同机制,弥补术前静态评估与术中动态验证的技术断层;<br> 2. 针对双侧肝胆管结石、合并肝萎缩等复杂病例,建立基于联合技术的个体化手术方案<document id="35"></document><document id="39"></document>。 </div> <h2 class="level2">六、参考文献</h2> <div class="reference">[1] Fang CH, et al. Outcomes of Hepatectomy for Hepatolithiasis Based on 3-Dimensional Reconstruction Technique. J Am Coll Surg, 2013, 217(2):280-288.<document id="2"></document></div> <div class="reference">[2] 王小方, 等. 三维可视化在解剖性肝切除治疗肝胆管结石中的应用效果. 中国当代医药, 2023, 30(6):59-62.<document id="3"></document></div> <div class="reference">[3] 范应方, 等. 3D技术在精准肝胆管结石外科诊治中的应用研究. 南方医科大学博士学位论文, 2021.<document id="4"></document></div> <div class="reference">[4] Zhang ZH, et al. Value of multidisciplinary team in minimally invasive treatment of complex intrahepatic bile duct stones. BioScience Trends, 2021, 15(3):161-170.<document id="8"></document></div> <div class="reference">[5] 三维可视化技术在腹腔镜解剖性肝切除治疗Ⅰ型肝胆管结石病中的应用. 中国普通外科杂志, 2022, 31(5):621-627.<document id="38"></document></div> <div class="reference">[6] 三维可视化技术在复杂肝胆管结石病中的应用研究. 中华外科杂志, 2020, 58(8):612-617.<document id="35"></document></div> <div class="reference">[7] Yang ZQ, et al. Application of three-dimensional visualization technology in early surgical repair of bile duct injury during laparoscopic cholecystectomy. BMC Surgery, 2024, 24:271.<document id="6"></document></div> <div class="reference">[8] 解剖性肝切除治疗复发性肝胆管结石病. 中华肝胆外科杂志, 2021, 27(3):176-179.<document id="31"></document></div> <div class="btn-container"> <a href="#" class="download-btn">下载Word文档</a> </div>直接运行,提供word下载按钮
最新发布
07-28
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值