Ticket No. 128M 0.1s ticket.cpp
Escription
Konjac konjac hzwer NOIP2014 miserable kneeling, he vaguely remember his ticket number is Notoginseng, now hzwer will face a game, he hope the ticket number does not appear Panax Notoginseng(continuous), at the same time he is very annoying 4, so also hope that 4 appear in the ticket number ... Now he wants to know How many valid ticket numbers are in between a and B .
Input
Contains two integers,A B
Output
An integer.
Sample Input
"Input Sample One"
1 10
"Input Sample Two"
25 50
Sample Output
"Output Example One"
9
"Output Example II"
14
"Data size and conventions"
20% data, meet 1 <= A <= B <= 1000000 .
100% data, meet 1 <= A <= B <= 2000000000 .
Digital DP
Nothing but f[i][j] means the number of I bits the first bit is the number of schemes of J and then messed up
I'm so weak ... Huang Huge says I write code the same style as * *
#include <cstdio> #include <iostream> #include <cstring> #include <cstdlib> #include < algorithm> #include <cmath> #include <queue> #include <deque> #include <set> #include <map > #include <ctime> #define LL long long#define INF 0x7ffffff#define pa pair<int,int> #define Pi 3.1415926535897932384626433832795028841971using namespace Std;inline ll read () {ll x=0,f=1;char Ch=getchar (); while (ch< ' 0 ' | | Ch> ' 9 ') {if (ch== '-') F=-1;ch=getchar ();} while (ch>= ' 0 ' &&ch<= ' 9 ') {x=x*10+ch-' 0 '; Ch=getchar ();} return x*f;} int f[20][10]; LL A, B; LL sec[20];inline void Pre () {sec[0]=1;for (int i=1;i<=15;i++) sec[i]=sec[i-1]*10;f[1][4]=1;for (int i=2;i<=12;i+ +) {for (int. j=0;j<=9;j++) {for (int k=0;k<=9;k++) f[i][j]+=f[i-1][k];} F[I][3]+=SEC[I-2]-F[I-1][7];F[I][4]=SEC[I-1];}} Inline LL Calc (LL x) {if (x<1) return 0;int dig[20]={0},len=0; LL Tot=0,dat=x;while (x) {dig[++len]=x%10;x/=10;} while (Len) {for (int i=0;i<dig[len];i++)tot+= (LL) f[len][i];if (dig[len]==4) {tot+= (LL) dat%sec[len-1]+1;break;} if (dig[len+1]==3&&dig[len]==7) {tot+= (LL) dat%sec[len-1]+1;break;} if (dig[len+1]==3&&dig[len]>7) {tot-= (LL) f[len][7];tot+=sec[len-1];} len--; }return Dat-tot;} int main () {freopen ("ticket.in", "R", stdin), Freopen ("Ticket.out", "w", stdout);p Re (), A=read (), B=read ();p rintf ("%d\n ", Calc (b)-calc (A-1)); return 0;}
2014.12.13 Simulation "Ticket Number"