首页 > 其他 > 详细

codeforces1169D

时间:2020-08-16 16:25:20      阅读:70      评论:0      收藏:0      [点我收藏+]

给你一个由01组成的序列,问你有多少对x,y使得[x,y]里面可以找到三位置他们等差且值相同。

例如:010101中1,5;2,6;1,6;有三对。

解法:构建一个等差子序列的左侧temp。遍历整个序列。对每一个位置遍历等差子序列的差值,找到它前面是否能构成等差子序列。如果找到的那个位置小于temp或者找不到时,答案直接加上temp(作为前面已经有的等差子序列的右侧y)。否则更新temp并加上贡献。

 

技术分享图片
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<map>
#include<queue>
#include<vector>
#include<string>
#define ll long long
#define PI acos(-1.0)
#define F first
#define S second
#define pb push_back
#define debug(x); printf("debug%d\n",x);
#define des(x); printf("des:%s\n",x+1);
const ll INF=0x3f3f3f3f3f3f3f3f;
const int inf=0x3f3f3f3f;
const ll mod=1e9+7;
using namespace std;
const int N=3e5+5;
char s[N];
int main()
{
    scanf("%s",s+1);
    int len=strlen(s+1);
    ll ans=0;
    int temp=0;
    for(int i=1;i<=len;i++)
    {
        for(int j=1;i-2*j>=temp;j++)
        {
            if(s[i]==s[i-j]&&s[i]==s[i-2*j])
            {
                temp=i-2*j;
                break;
            }
        }
        ans+=(ll)(temp);
    }
    printf("%lld\n",ans);
    return 0;
}
View Code

 

codeforces1169D

原文:https://www.cnblogs.com/switch-waht/p/13512719.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!