2012百度之星初赛第一场B题
小弟新手,只尝试了B题,还各种bug。改过之后的代码是:
#include <stdio.h> long long pow(long long x) { long long a=10; while(x/a!=0) { a*=10; } return a; } int main() { int n,i,s=0; long long x,a,b,p; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%lld%lld%lld",&x,&a,&b); p=pow(x); if(a%p>x)s--; if(b%p<x)s--; a=a/p; b=b/p; s+=(b-a+1); printf("%d\n",s); s=0; } return 0; }
希望是正确的。但有一点可以肯定,不能依次递增比较[a,b]区间内的所有数,如果给定的区间很大,很容易超时,因为给定的范围是10^18。