标签:des style blog io ar os sp for java
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 8554 Accepted Submission(s): 2981
#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.1415926535897932384626433832795028841971 using 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; } inline void write(LL a) { if (a<0){printf("-");a=-a;} if (a>=10)write(a/10); putchar(a%10+‘0‘); } inline void writeln(LL a){write(a);printf("\n");} int n; LL f[30][10]; LL sec[20]; inline LL wrk(LL x) { LL tot=0,dat=x; int dig[20]={0},len=0; while (x) { dig[++len]=x%10; x/=10; } while (len) { dat-=dig[len]*sec[len-1]; for (int i=0;i<dig[len];i++) tot+=f[len][i]; if (dig[len+1]==4&&dig[len]==9) { tot+=dat+1; break; } len--; } return tot; } int main() { n=read(); sec[0]=1;for(int i=1;i<=17;i++)sec[i]=sec[i-1]*10; for (int i=2;i<=20;i++) for (int j=0;j<10;j++) { for (int k=0;k<10;k++)f[i][j]+=f[i-1][k]; if (j==4)f[i][j]+=sec[i-2]-f[i-1][9]; } for(int i=1;i<=n;i++) { LL x=read(); writeln(wrk(x)); } return 0; }
标签:des style blog io ar os sp for java
原文地址:http://www.cnblogs.com/zhber/p/4160521.html