Codeforces 628B New Skateboard【数学】

来源:互联网 发布:淘宝宝贝复制破解 编辑:程序博客网 时间:2024/05/29 19:01


题目链接:点我

题意:给定一个数字串,问可以被4整除的子串有多少个?可以有前缀0。

——能被4整除的数:末尾的两位数必定是4的倍数。暴力扫一遍就好了。


AC代码:


#include <iostream>#include <string>#include <cstdio>#include <cmath>#include <algorithm>#include <cstdlib>#define CLR(a, b) memset(a, (b), sizeof(a))#define PI acos(-1.0)using namespace std;typedef long long LL;typedef double DD;const int MAXN = 3*1e5+10;int main(){    string str; cin >> str;    int len = str.size();    LL ans = 0;    for(int i = 0; i < len; i++)    {        int v = str[i] - '0';        ans += 1LL*(v % 4 == 0);        if(i)        {            int yu = ((str[i-1] - '0') * 10 + v) % 4;            if(yu == 0)                ans += 1LL*i;        }    }    cout << ans << endl;    return 0;}



0 0
原创粉丝点击