标签:ram ret return pos acm pre ring class std
//Serene #include<algorithm> #include<iostream> #include<cstring> #include<cstdlib> #include<cstdio> #include<cmath> using namespace std; const int maxn=1e6+10; int l,r,mi[maxn],dp[12][2],ans; int aa;char cc; int read() { aa=0;cc=getchar(); while(cc<‘0‘||cc>‘9‘) cc=getchar(); while(cc>=‘0‘&&cc<=‘9‘) aa=aa*10+cc-‘0‘,cc=getchar(); return aa; } int len(int x) { int rs=0;while(x) { rs++;x/=10; } return rs;} int f(int pos,int p) {//2:lim 1:last==6 if(!pos) return 1; if(!(p&2)&&dp[pos][p]!=-1) return dp[pos][p]; int d= (p&2)? (r/mi[pos-1])%10 : 9,rs=0; for(int i=0;i<=d;++i) if(i!=4&&!(p&(i==2))) rs+=f(pos-1,(p&((i==d)<<1))+(i==6)); if(!(p&2)) dp[pos][p]=rs; return rs; } int main() { l=read();r=read(); mi[0]=1; for(int i=1;i<=10;++i) mi[i]=mi[i-1]*10; memset(dp,-1,sizeof(dp)); while(r) { ans=f(len(r),2);r=l-1; ans-=f(len(r),2); printf("%d\n",ans); l=read();r=read(); } return 0; }
标签:ram ret return pos acm pre ring class std
原文地址:http://www.cnblogs.com/Serene-shixinyi/p/7629329.html