Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final)

最近有点学不动了,就来填一下坑

cf #504

A

简单但又带点坑的模拟题,*号可以代替任何字符串,还可以为空,那么前后遍历一遍就可以了(细节没处理好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;
}

B:Pair of Toys

水题,在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;
}

C: Bracket Subsequence

还是水题,选出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;
}

D: Array Restoration

有空补

E:Down or Right

有空补

咕咕咕

(拖了有点久,但是问题不大,反正也没人看)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值