Codeforces 628B - New Skateboard

628B - New Skateboard

思路:dp

代码:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ls rt<<1,l,m
#define rs rt<<1|1,m+1,r
const int INF=0x3f3f3f3f;
const int N=3e5+5;
ll dp[N]={0};
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin>>s;
    ll ans=0;
    if((s[0]-‘0‘)%4==0)dp[0]=1;
    for(int i=1;i<s.size();i++)
    {
        int x=s[i]-‘0‘;
        if(x%4==0)dp[i]=dp[i-1]+1;
        else dp[i]=dp[i-1];
        int y=s[i-1]-‘0‘;
        int n=y*10+x;
        if(n%4==0)dp[i]+=i;
    }
    cout<<dp[s.size()-1]<<endl;
    return 0;
}
时间: 2024-10-06 15:57:25

Codeforces 628B - New Skateboard的相关文章

CF 628B New Skateboard --- 水题

CD 628B 题目大意:给定一个数字(<=3*10^5),判断其能被4整除的连续子串有多少个 解题思路:注意一个整除4的性质: 若bc能被4整除,则a1a2a3a4...anbc也一定能被4整除: 利用这个性质,先特判第一位数字是否能被4整除,可以则++cnt, 之后从第二位数字开始,设当前位为i,先判断a[i]能否被4整除,可以则++cnt, 再判断a[i-1]*10+a[i]能否被4整除,可以则cnt = cnt + (i) 相关证明: 设一整数各个位置为a1,a2,a3,...,an,b

Codeforces 682B New Skateboard(DP)

题目大概说给一个数字组成的字符串问有几个子串其代表的数字(可以有前导0)能被4整除. dp[i][m]表示字符串0...i中mod 4为m的后缀的个数 通过在i-1添加str[i]字符转移,或者以str[i]为新后缀的开头转移 1 #include<cstdio> 2 #include<cstring> 3 using namespace std; 4 char str[333333]; 5 long long d[333333][4]; 6 int main(){ 7 scanf

SZU3

CodeForces 343A 这是第一题,像这种水题一定不要想复杂,思路不对立马换. 抓住串联和并联,可以用辗转相除法 #include <iostream> #include <string> #include <cstring> #include <cstdlib> #include <cstdio> #include <cmath> #include <algorithm> #include <stack&g

[2016-04-08][codeforces][628][B][New Skateboard]

时间:2016-04-08 13:24:57 星期五 题目编号:[2016-04-08][codeforces][628][B][New Skateboard] 题目大意:给定一个长度最大为3×1053×105的字符串,问有多少个能被4整除的子串, 分析: 每个数字后面两位数能被4整除,那么这个数字就能被4整除 dp[i]表示从0~i这一段字符能被4整除的数目,那么dp[i] = dp[i - 1] + (a[i]%4 == 0) + ((a[i-1] * 10 + a[i])%4?0:i) 即

Educational Codeforces Round 8 B. New Skateboard

题目链接:http://codeforces.com/problemset/problem/628/B 解题思路: 一个数最后两位数能被4整除那么这个数就能被4整除,而且题目还是连续的子序列,这就很简单了 实现代码: #include <cstdio> #include <string> #include <iostream> #include <algorithm> #include <vector> #include <queue>

【codeforces 718E】E. Matvey&#39;s Birthday

题目大意&链接: http://codeforces.com/problemset/problem/718/E 给一个长为n(n<=100 000)的只包含‘a’~‘h’8个字符的字符串s.两个位置i,j(i!=j)存在一条边,当且仅当|i-j|==1或s[i]==s[j].求这个无向图的直径,以及直径数量. 题解:  命题1:任意位置之间距离不会大于15. 证明:对于任意两个位置i,j之间,其所经过每种字符不会超过2个(因为相同字符会连边),所以i,j经过节点至多为16,也就意味着边数至多

Codeforces 124A - The number of positions

题目链接:http://codeforces.com/problemset/problem/124/A Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people standing b

Codeforces 841D Leha and another game about graph - 差分

Leha plays a computer game, where is on each level is given a connected graph with n vertices and m edges. Graph can contain multiple edges, but can not contain self loops. Each vertex has an integer di, which can be equal to 0, 1 or  - 1. To pass th

Codeforces Round #286 (Div. 1) A. Mr. Kitayuta, the Treasure Hunter DP

链接: http://codeforces.com/problemset/problem/506/A 题意: 给出30000个岛,有n个宝石分布在上面,第一步到d位置,每次走的距离与上一步的差距不大于1,问走完一路最多捡到多少块宝石. 题解: 容易想到DP,dp[i][j]表示到达 i 处,现在步长为 j 时最多收集到的财富,转移也不难,cnt[i]表示 i 处的财富. dp[i+step-1] = max(dp[i+step-1],dp[i][j]+cnt[i+step+1]) dp[i+st