最近有点学不动了,就来填一下坑
cf #504
简单但又带点坑的模拟题,*号可以代替任何字符串,还可以为空,那么前后遍历一遍就可以了(细节没处理好fst了,本来被人hack了一发,然后以为改的很完美了,然而在第87组数据wa了
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
const int maxn = 2e5+10;
char s1[maxn],s2[maxn];
int main()
{
ios::sync_with_stdio(false);
int n,m;cin>>n>>m;
cin>>s1>>s2;
int wz=-1;
for(int i=0;i<n;i++)
if(s1[i]=='*')
{
wz=i;
break;
}
if(wz==-1&&n!=m)puts("NO");
else
{
if(wz>=0 && n-1>m)puts("NO");
else if(wz==-1)
{
int flag=1;
for(int i=0;i<n;i++)
if(s1[i]!=s2[i])
{
flag=0;
break;
}
if(flag)puts("YES");
else puts("NO");
}
else
{
int flag=1;
for(int i=0;i<wz;i++)
if(s1[i]!=s2[i])
flag=0;
for(int i=1;n-i>wz;i++)
if(s1[n-i]!=s2[m-i]||m-i<wz)
flag=0;
if(flag)puts("YES");
else puts("NO");
}
}
return 0;
}
水题,在n个玩具中选两个,使其价格和为k。
#include<cstdio>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
int main()
{
ios::sync_with_stdio(false);
ll n,k;
cin>>n>>k;
ll ca=k-n;
if(n>=k-1)cout<<(k-1)/2<<endl;
else if(ca>=n)cout<<0<<endl;
else cout<<(n-ca+1)/2<<endl;
return 0;
}
还是水题,选出k对合理的括号,直接上代码把。
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
const int maxn = 2e5+10;
char s[maxn];
int main()
{
ios::sync_with_stdio(false);
int n,m;cin>>n>>m;
cin>>s;
int i=0,j=0;
m>>=1;
for(int k=0;k<n;k++)
{
if(s[k]=='('&&i<m)
{
cout<<'(';
i++;
}
else if(s[k]==')'&&j<m&&j+1<=i)//源代码我这里没加j+1<=i这个条件,但还是a了,可能是没人hack吧
{
cout<<')';
j++;
}
}
cout<<endl;
return 0;
}
有空补
有空补
咕咕咕
(拖了有点久,但是问题不大,反正也没人看)