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

Source: Internet
Author: User

  • Time: 2016-04-08-13:24:57
  • Title Number: [2016-04-08][codeforces][628][b][new skateboard]
  • The main topic: given a length of the most 3x5 3 x 5 String, asking how many substrings can be divisible by 4,
  • Analysis:
    • Two digits after each number can be divisible by 4, then this number will be divisible by 4.
    • Dp[i] Indicates the number of words RP divisible by 4 from 0~i, then dp[i] = dp[i-1] + (a[i]%4 = 0) + ((a[i-1] * + a[i])%4?0:i)
      • That is, if the potential of the first can be divisible by 4, then the answer is +1, if the second bit is added, the next two bits are divisible by 4, then the answer is to add I, because the string containing the next two bits have I
  
 
  1. #include <cstring>
  2. #include <cstdio>
  3. using namespace std;
  4. typedef long long LL;
  5. const int maxn = 3 * 1E5 + 10;
  6. char str[maxn];
  7. int main(){
  8. scanf("%s",str);
  9. int n = strlen(str);
  10. LL ans = 0;int tmp;
  11. for(int i = 0 ; i < n; ++i){
  12. int tmp = str[i] - ‘0‘;
  13. if(tmp % 4 == 0) ++ans;
  14. if(i){
  15. tmp = Span class= "PLN" > ( str [ i - 1 - ' 0 ' 10 + tmp
  16. if(tmp % 4 == 0) ans += i;
  17. }
  18. }
  19. printf("%I64d\n",ans);
  20. return 0;
  21. }


From for notes (Wiz)

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.