[Scoi 2009]windy number

Source: Internet
Author: User

Description

Question Bank link

Find out the number of positive integers in \ ([a,b]\) that satisfy the adjacent difference value of at least \ (2\) .

\ (1\leq a,b\leq 2\cdot 10^9\)

Solution

Digits \ (dp\) .

Or, according to the formula \ (f_{i,j}\) is the \ (i\) bit, the number of the first \ (1\) bit is \ (j\) satisfies the condition.

Then calculate the time to pay attention to if the previous number of digits is not satisfied, the direct exit.

Code
//it is made by Awson on 2018.2.25#include <bits/stdc++.h>#define LL Long Long#define DOB complex<double>#define ABS (a) ((a) < 0? (-(a)): (a))#define MAX (A, B) ((a) > (b)? (a): (b))#define Min (A, B) ((a) < (b)? (a): (b))#define SWAP (A, B) ((a) ^= (b), (b) ^= (a), (a) ^= (b))#define WRITELN (x) (write (x), Putchar ('\n '))#define LOWBIT (x) ((x) & (-(x )))using namespaceStdvoidRead (LL &x) {CharChBOOLFlag =0; for(ch = getchar ();!isdigit (CH) && (flag |= (ch = ='-')) ||1); ch = getchar ()); for(x =0; IsDigit (CH); x = (x<<1) + (x<<3) +ch-48, ch = getchar ()); X *=1-2*flag;}voidPrint (LL x) {if(X >9) Print (x/Ten); Putchar (%10+48); }voidWrite (LL x) {if(X <0) Putchar ('-'); Print (Abs (x)); }ll f[ -][Ten], A, b;voidPre () { for(inti =0; I <=9; i++) f[1][i] =1; for(inti =2; I <=Ten; i++) { for(intj =0; J <=9; J + +) { for(intK =0; K <= J-2; k++) f[i][j] + = F[i-1][K]; for(intK = J+2; K <=9; k++) f[i][j] + = F[i-1][K]; }}}ll Get (intx) {inta[ -], tot =0; LL ans =0; while(x) A[++tot] =x%Ten, x/=Ten; for(inti = Tot-1; I >=1; i--) for(intj =1; J <=9; J + +) ans + = f[i][j]; for(inti =1; i < A[tot]; i++) ans + = f[tot][i]; for(inti = Tot-1, last = A[tot]; I >=1; i--) { for(intj =0; J < A[i]; J + +) {if(Abs (J-last) <2)Continue;    Ans + = f[i][j]; } last = A[i];if(Abs (a[i+1]-a[i]) <2) Break; }returnAns;}voidWork () {pre (); Read (a), read (b); Writeln (Get (b+1)-get (a));}intMain () {work ();return 0;}

[Scoi 2009]windy number

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.