标签:display 思路 std a* clu code fine 计算 space
windy定义了一种windy数。不含前导零且相邻两个数字之差至少为2的正整数被称为windy数。 windy想知道,
在A和B之间,包括A和B,总共有多少个windy数?
包含两个整数,A B。
输出格式:一个整数
1 10
9
25 50
20
100%的数据,满足 1 <= A <= B <= 2000000000 。
Solution:
本题显然数位$DP$,暂时不会(留着填坑~)。
提供打表的思路,先线下每$10^6$个处理一次,统计出$2000$个答案(前缀和$sum[i]$表示$1$到$i*10^6$中满足条件的个数)。
那么查询时就直接瞎搞模拟,最多计算$10^6$次。
打表代码:
1 /************************************************************** 2 Problem: 1026 3 User: five20 4 Language: C++ 5 Result: Accepted 6 Time:256 ms 7 Memory:1296 kb 8 ****************************************************************/ 9 10 #include<iostream> 11 #include<cstdio> 12 #include<algorithm> 13 #include<cmath> 14 #define For(i,a,b) for(int (i)=(a);(i)<=(b);(i)++) 15 using namespace std; 16 const int N=1e6+5; 17 int ans,a,b,sum[2005]={0, 202174, 136131, 138503, 138214, 138252, 138252, 138214, 138503, 136131, 155315, 0, 0, 0, 138214, 138252, 138252, 138214, 138503, 136131, 155315, 155315, 0, 0, 0, 138252, 138252, 138214, 138503, 136131, 155315, 155315, 136131, 0, 0, 0, 138252, 138214, 138503, 136131, 155315, 155315, 136131, 138503, 0, 0, 0, 138214, 138503, 136131, 155315, 155315, 136131, 138503, 138214, 0, 0, 0, 138503, 136131, 155315, 155315, 136131, 138503, 138214, 138252, 0, 0, 0, 136131, 155315, 155315, 136131, 138503, 138214, 138252, 138252, 0, 0, 0, 155315, 155315, 136131, 138503, 138214, 138252, 138252, 138214, 0, 0, 0, 155315, 136131, 138503, 138214, 138252, 138252, 138214, 138503, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 155315, 136131, 0, 0, 0, 138252, 138214, 138503, 136131, 155315, 155315, 136131, 138503, 0, 0, 0, 138214, 138503, 136131, 155315, 155315, 136131, 138503, 138214, 0, 0, 0, 138503, 136131, 155315, 155315, 136131, 138503, 138214, 138252, 0, 0, 0, 136131, 155315, 155315, 136131, 138503, 138214, 138252, 138252, 0, 0, 0, 155315, 155315, 136131, 138503, 138214, 138252, 138252, 138214, 0, 0, 0, 155315, 136131, 138503, 138214, 138252, 138252, 138214, 138503, 0, 0, 0, 0, 138503, 138214, 138252, 138252, 138214, 138503, 136131, 155315, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 155315, 136131, 138503, 0, 0, 0, 138214, 138503, 136131, 155315, 155315, 136131, 138503, 138214, 0, 0, 0, 138503, 136131, 155315, 155315, 136131, 138503, 138214, 138252, 0, 0, 0, 136131, 155315, 155315, 136131, 138503, 138214, 138252, 138252, 0, 0, 0, 155315, 155315, 136131, 138503, 138214, 138252, 138252, 138214, 0, 0, 0, 155315, 136131, 138503, 138214, 138252, 138252, 138214, 138503, 0, 0, 0, 0, 138503, 138214, 138252, 138252, 138214, 138503, 136131, 155315, 0, 0, 0, 138214, 138252, 138252, 138214, 138503, 136131, 155315, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 155315, 136131, 138503, 138214, 0, 0, 0, 138503, 136131, 155315, 155315, 136131, 138503, 138214, 138252, 0, 0, 0, 136131, 155315, 155315, 136131, 138503, 138214, 138252, 138252, 0, 0, 0, 155315, 155315, 136131, 138503, 138214, 138252, 138252, 138214, 0, 0, 0, 155315, 136131, 138503, 138214, 138252, 138252, 138214, 138503, 0, 0, 0, 0, 138503, 138214, 138252, 138252, 138214, 138503, 136131, 155315, 0, 0, 0, 138214, 138252, 138252, 138214, 138503, 136131, 155315, 155315, 0, 0, 0, 138252, 138252, 138214, 138503, 136131, 155315, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 155315, 136131, 138503, 138214, 138252, 0, 0, 0, 136131, 155315, 155315, 136131, 138503, 138214, 138252, 138252, 0, 0, 0, 155315, 155315, 136131, 138503, 138214, 138252, 138252, 138214, 0, 0, 0, 155315, 136131, 138503, 138214, 138252, 138252, 138214, 138503, 0, 0, 0, 0, 138503, 138214, 138252, 138252, 138214, 138503, 136131, 155315, 0, 0, 0, 138214, 138252, 138252, 138214, 138503, 136131, 155315, 155315, 0, 0, 0, 138252, 138252, 138214, 138503, 136131, 155315, 155315, 136131, 0, 0, 0, 138252, 138214, 138503, 136131, 155315, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 155315, 136131, 138503, 138214, 138252, 138252, 0, 0, 0, 155315, 155315, 136131, 138503, 138214, 138252, 138252, 138214, 0, 0, 0, 155315, 136131, 138503, 138214, 138252, 138252, 138214, 138503, 0, 0, 0, 0, 138503, 138214, 138252, 138252, 138214, 138503, 136131, 155315, 0, 0, 0, 138214, 138252, 138252, 138214, 138503, 136131, 155315, 155315, 0, 0, 0, 138252, 138252, 138214, 138503, 136131, 155315, 155315, 136131, 0, 0, 0, 138252, 138214, 138503, 136131, 155315, 155315, 136131, 138503, 0, 0, 0, 138214, 138503, 136131, 155315, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 155315, 136131, 138503, 138214, 138252, 138252, 138214, 0, 0, 0, 155315, 136131, 138503, 138214, 138252, 138252, 138214, 138503, 0, 0, 0, 0, 138503, 138214, 138252, 138252, 138214, 138503, 136131, 155315, 0, 0, 0, 138214, 138252, 138252, 138214, 138503, 136131, 155315, 155315, 0, 0, 0, 138252, 138252, 138214, 138503, 136131, 155315, 155315, 136131, 0, 0, 0, 138252, 138214, 138503, 136131, 155315, 155315, 136131, 138503, 0, 0, 0, 138214, 138503, 136131, 155315, 155315, 136131, 138503, 138214, 0, 0, 0, 138503, 136131, 155315, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 155315, 136131, 138503, 138214, 138252, 138252, 138214, 138503, 0, 0, 0, 0, 138503, 138214, 138252, 138252, 138214, 138503, 136131, 155315, 0, 0, 0, 138214, 138252, 138252, 138214, 138503, 136131, 155315, 155315, 0, 0, 0, 138252, 138252, 138214, 138503, 136131, 155315, 155315, 136131, 0, 0, 0, 138252, 138214, 138503, 136131, 155315, 155315, 136131, 138503, 0, 0, 0, 138214, 138503, 136131, 155315, 155315, 136131, 138503, 138214, 0, 0, 0, 138503, 136131, 155315, 155315, 136131, 138503, 138214, 138252, 0, 0, 0, 136131, 155315, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 138503, 138214, 138252, 138252, 138214, 138503, 136131, 155315, 0, 0, 0, 138214, 138252, 138252, 138214, 138503, 136131, 155315, 155315, 0, 0, 0, 138252, 138252, 138214, 138503, 136131, 155315, 155315, 136131, 0, 0, 0, 138252, 138214, 138503, 136131, 155315, 155315, 136131, 138503, 0, 0, 0, 138214, 138503, 136131, 155315, 155315, 136131, 138503, 138214, 0, 0, 0, 138503, 136131, 155315, 155315, 136131, 138503, 138214, 138252, 0, 0, 0, 136131, 155315, 155315, 136131, 138503, 138214, 138252, 138252, 0, 0, 0, 155315, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0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503, 136131, 155315, 155315, 136131, 138503, 138214, 138252, 0, 0, 0, 136131, 155315, 155315, 136131, 138503, 138214, 138252, 138252, 0, 0, 0, 155315, 155315, 136131, 138503, 138214, 138252, 138252, 138214, 0, 0, 0, 155315, 136131, 138503, 138214, 138252, 138252, 138214, 138503, 0, 0, 0, 0, 138503, 138214, 138252, 138252, 138214, 138503, 136131, 155315, 0, 0, 0, 138214, 138252, 138252, 138214, 138503, 136131, 155315, 155315, 0, 0, 0, 138252, 138252, 138214, 138503, 136131, 155315, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 155315, 136131, 138503, 138214, 138252, 0, 0, 0, 136131, 155315, 155315, 136131, 138503, 138214, 138252, 138252, 0, 0, 0, 155315, 155315, 136131, 138503, 138214, 138252, 138252, 138214, 0, 0, 0, 155315, 136131, 138503, 138214, 138252, 138252, 138214, 138503, 0, 0, 0, 0, 138503, 138214, 138252, 138252, 138214, 138503, 136131, 155315, 0, 0, 0, 138214, 138252, 138252, 138214, 138503, 136131, 155315, 155315, 0, 0, 0, 138252, 138252, 138214, 138503, 136131, 155315, 155315, 136131, 0, 0, 0, 138252, 138214, 138503, 136131, 155315, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 155315, 136131, 138503, 138214, 138252, 138252, 0, 0, 0, 155315, 155315, 136131, 138503, 138214, 138252, 138252, 138214, 0, 0, 0, 155315, 136131, 138503, 138214, 138252, 138252, 138214, 138503, 0, 0, 0, 0, 138503, 138214, 138252, 138252, 138214, 138503, 136131, 155315, 0, 0, 0, 138214, 138252, 138252, 138214, 138503, 136131, 155315, 155315, 0, 0, 0, 138252, 138252, 138214, 138503, 136131, 155315, 155315, 136131, 0, 0, 0, 138252, 138214, 138503, 136131, 155315, 155315, 136131, 138503, 0, 0, 0, 138214, 138503, 136131, 155315, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 155315, 136131, 138503, 138214, 138252, 138252, 138214, 0, 0, 0, 155315, 136131, 138503, 138214, 138252, 138252, 138214, 138503, 0, 0, 0, 0, 138503, 138214, 138252, 138252, 138214, 138503, 136131, 155315, 0, 0, 0, 138214, 138252, 138252, 138214, 138503, 136131, 155315, 155315, 0, 0, 0, 138252, 138252, 138214, 138503, 136131, 155315, 155315, 136131, 0, 0, 0, 138252, 138214, 138503, 136131, 155315, 155315, 136131, 138503, 0, 0, 0, 138214, 138503, 136131, 155315, 155315, 136131, 138503, 138214, 0, 0, 0, 138503, 136131, 155315, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 155315, 136131, 138503, 138214, 138252, 138252, 138214, 138503, 0, 0, 0, 0, 138503, 138214, 138252, 138252, 138214, 138503, 136131, 155315, 0, 0, 0, 138214, 138252, 138252, 138214, 138503, 136131, 155315, 155315, 0, 0, 0, 138252, 138252, 138214, 138503, 136131, 155315, 155315, 136131, 0, 0, 0, 138252, 138214, 138503, 136131, 155315, 155315, 136131, 138503, 0, 0, 0, 138214, 138503, 136131, 155315, 155315, 136131, 138503, 138214, 0, 0, 0, 138503, 136131, 155315, 155315, 136131, 138503, 138214, 138252, 0, 0, 0, 136131, 155315, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 138503, 138214, 138252, 138252, 138214, 138503, 136131, 155315, 0, 0, 0, 138214, 138252, 138252, 138214, 138503, 136131, 155315, 155315, 0, 0, 0, 138252, 138252, 138214, 138503, 136131, 155315, 155315, 136131, 0, 0, 0, 138252, 138214, 138503, 136131, 155315, 155315, 136131, 138503, 0, 0, 0, 138214, 138503, 136131, 155315, 155315, 136131, 138503, 138214, 0, 0, 0, 138503, 136131, 155315, 155315, 136131, 138503, 138214, 138252, 0, 0, 0, 136131, 155315, 155315, 136131, 138503, 138214, 138252, 138252, 0, 0, 0, 155315, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; 18 inline void check(int x){ 19 if(x<=9){ans++;return;} 20 int a=x,b=-5; 21 while(a){ 22 if(abs(a%10-b)<2)return; 23 b=a%10;a=a/10; 24 } 25 ans++; 26 } 27 int main(){ 28 cin>>a>>b; 29 if(b-a<=1000000){ 30 For(i,a,b)check(i); 31 cout<<ans; 32 return 0; 33 } 34 int p=ceil(a*1.0/1000000),q=floor(b*1.0/1000000); 35 For(i,1,2000)sum[i]+=sum[i-1]; 36 ans+=sum[q]-sum[p]; 37 if(!ans)ans++; 38 p=p*1000000,q=q*1000000; 39 if(a!=p) 40 For(i,a,p-1)check(i); 41 if(b!=q) 42 For(i,q+1,b)check(i); 43 cout<<ans; 44 return 0; 45 }
标签:display 思路 std a* clu code fine 计算 space
原文地址:https://www.cnblogs.com/five20/p/9040490.html