SCAU2021暑期组队排位赛 #2

J
s中至少一次将t作为子序列包含的s的子字符串数

#include<stdio.h>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iostream>

#define PI 2*acos(0.0)
#define ll long long
#define INT_MAX 2147483647

using namespace std;
string s,t;
int main()
{
	cin>>s>>t;
	int lens=s.size(),lent=t.size();
	int pos=-1,tt,ss; long long ans=0;
	while (true)
    {
        ss=s.find(t[0],pos+1);
        if (ss==-1) break;
        tt=ss;
        for (int i=1;i<lent;i++)
        {
            tt=s.find(t[i],tt+1);
            if (tt==-1) break;
        }
        if (tt==-1) break;
        ans+=(ss-pos)*(lens-tt);
        pos=ss;
    }
    cout<<ans;
	return 0;
}

D
【题解】类欧几里得
在这里插入图片描述

#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define mst(a,b) memset(a,b,sizeof a)

#define PI 2*acos(0.0)
#define ll long long
#define INT_MAX 2147483647

using namespace std;
ll t,p,q,n;
ll f(ll a,ll b,ll c,ll n)
{
    if (a==0) return (n+1)*(b/c);
    if (a<c && b<c)
    {
        ll m=(a*n+b)/c;
        if (m==0) return 0;
        return n*m-f(c,c-b-1,a,m-1);
    }
    return f(a%c,b%c,c,n)+(n+1)*(b/c)+((n+1)/(1+(n&1)))*(n/(2-(n&1)))*(a/c);
}
int main()
{
    IOS
    cin>>t;
    while (t--)
    {
        cin>>p>>q>>n;
        ll sum=f(p,0,q,n);
        cout<<p*n*(n+1)/2-sum*q<<endl;
    }
    return 0;
}

模板链接

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值