B题
当p=0时所有的总分都在sum1++,
当p=1时,总分>=1时在sum1++,总分==0,是无论如何都满足不了题意(坑点);
总分>=29时是没有surprising情况的,无论p取何值都在sum1++;
#include<cstdio> #include<cstring> using namespace std; int main(){ int n,i,j,T,t,s,p,a; char ch; freopen( "B-large.in", "r", stdin ); freopen( "output1.out", "w", stdout ); scanf("%d",&T); for(t=1;t<=T;t++){ printf("Case #%d: ",t); int sum1=0,sum2=0,sum=0; scanf("%d %d %d",&n,&s,&p); for(i=1;i<=n;i++){ scanf("%d",&a); if(a>=p*3-2) sum1++; else if(a==0 && p==1) ; else if(a>=p*3-4) sum2++; } if(sum2>s) printf("%d\n",s+sum1); else printf("%d\n",sum1+sum2); } }
C题
这个题有个易错点。就是1212这种自身带循环节的情况。
易分析如果一个数移位后得到自身,那么此数一定有循环节。
#include<cstdio> #include<cstring> #include<math.h> using namespace std; int main(){ int i,j,T,t,a,b,n,p; char ch; freopen("C-large.in","r",stdin); freopen("output1.out","w",stdout); scanf("%d",&T); for(t=1;t<=T;t++){ printf("Case #%d: ",t); scanf("%d %d",&a,&b); if(a<10) printf("0\n"); else{ int n=(int)log10((double)b)+1; int con=(int )pow((double)10,(double)n); int sum=0; for(i=a;i<=b;i++){ int tem1,tem2=a; p=10; while(1){ tem1=i%p; tem2=i/p; if(tem1*(con/p)+tem2==i) ////// break; if(tem1*(con/p)+tem2>i && tem1*(con/p)+tem2<=b) sum++; p*=10; } } printf("%d\n",sum); } } }