Bomb
Time limit:2000/1000 MS (java/others) Memory limit:131072/65536 K (java/others)
Total submission (s): 15072 Accepted Submission (s): 5441
Problem DescriptionThe Counter-terrorists found a time bomb in the dust. But this time, the terrorists improve on the time bomb. The number sequence of the time bomb counts from 1 to N. If The current number sequence includes the Sub-sequence "a", the power of the blast would add one point.
Now the counter-terrorist knows the number N. They want to know the final points of the power. Can you help them?
Inputthe first line of input consists of an integer t (1 <= T <= 10000), indicating the number of test cases. For each test case, there'll be is an integer N (1 <= n <= 2^63-1) as the description.
The input terminates by end of file marker.
Outputfor each test case, output an integer indicating the final points of the power.
Sample Input3150500
Sample Output0115
HintFrom 1 to $, the numbers that include the Sub-sequence "is" 49 "," 149 "," 249 "," 349 "," 449 "," 490 "," 491 "," 492 "," 493 "," 49 4 "," 495 "," 496 "," 497 "," 498 "," 499 ", so the answer is 15.
Author[email protected]
Source2010 acm-icpc multi-university Training Contest (--host by WHU)
Test instructions: To find the number of "49" in the 1~n closed interval
Exercises
Dp[i][2] Length I contains the number of "49"
Dp[i][1] length I does not contain "49" but the number of "9" high
Dp[i][0] The length of I does not contain the number of "49"
Array A[i] stores every digit of n from low to high.
DP[I][2]=DP[I-1][2]*10+DP[I-1][1]; Consider the "4" i-1 bit "9" for the I-bit
DP[I][1]=DP[I-1][0];
DP[I][0]=DP[I-1][0]*10-DP[I-1][1];
Why do you want to increase your self by 1 before n processing
Because the problem is that the closed interval may be increased by 1 as an open interval processing
Http://www.cnblogs.com/liuxueyang/archive/2013/04/14/3020032.html
1 /******************************2 code by drizzle3 blog:www.cnblogs.com/hsd-/4 ^ ^ ^ ^5 o o6 ******************************/7 //#include <bits/stdc++.h>8#include <iostream>9#include <cstring>Ten#include <cstdio> One#include <map> A#include <algorithm> -#include <queue> - #definell __int64 the using namespacestd; - intT; - ll N; -ll a[ $]; +ll dp[ $][5]; - voidInit () + { Adp[0][0]=1; at for(intI=1; i<= A; i++) - { -dp[i][0]=Ten*dp[i-1][0]-dp[i-1][1]; -dp[i][1]=dp[i-1][0]; -dp[i][2]=Ten*dp[i-1][2]+dp[i-1][1]; - } in } - intMain () to { + init (); - while(SCANF ("%d", &t)! =EOF) the { * for(intI=1; i<=t; i++) $ {Panax Notoginsengscanf"%i64d",&n); -Memset (A,0,sizeof(a)); the intlen=1; +n++; A while(n) the { +a[len]=n%Ten; -n=n/Ten; $len++; $ } - intflag=0; - intlast=0; thell ans=0; - for(intJ=len; j>=1; j--)Wuyi { theans+=dp[j-1][2]*A[j]; - if(flag) Wuans+=dp[j-1][0]*A[j]; - if(!flag&&a[j]>4) Aboutans+=dp[j-1][1]; $ if(last==4&&a[j]==9) -flag=1; -last=A[j]; - } Aprintf"%i64d\n", ans); + } the } - return 0; $}
HDU 3555 Digit DP