标签:判断 col 模拟 main 树状 sum bit break class
取模判断,数组模拟
1 /* 2 Written By StelaYuri 3 */ 4 #include<stdio.h> 5 int a[1000010]; 6 int main(){ 7 int n,m,i,s,t; 8 for(i=1;i<1000001;i++){ 9 a[i]=1; 10 t=i; 11 while(t>0){ 12 if(t%10==4||t%100==62){ 13 a[i]=0; 14 break; 15 } 16 t/=10; 17 } 18 } 19 while(scanf("%d%d",&n,&m)!=EOF&&(n||m)){ 20 s=0; 21 for(i=n;i<=m;i++) 22 if(a[i]) 23 s++; 24 printf("%d\n",s); 25 } 26 27 return 0; 28 }
树状数组优化查找时间
1 /* 2 Written By StelaYuri 3 */ 4 #include<stdio.h> 5 #include<memory.h> 6 int a[1000010]; 7 int lowbit(int x){ 8 return x&(-x); 9 } 10 int sum(int in){ 11 int res=0; 12 while(in){ 13 res+=a[in]; 14 in-=lowbit(in); 15 } 16 return res; 17 } 18 void add(int in){ 19 while(in<=1000000){ 20 a[in]++; 21 in+=lowbit(in); 22 } 23 } 24 int main(){ 25 int n,m,jd,i,t; 26 memset(a,0,sizeof a); 27 for(i=1;i<1000001;i++){ 28 jd=1; 29 t=i; 30 while(t){ 31 if(t%10==4||t%100==62){ 32 jd=0; 33 break; 34 } 35 t/=10; 36 } 37 if(jd) 38 add(i); 39 } 40 while(scanf("%d%d",&n,&m)!=EOF&&(n||m)) 41 printf("%d\n",sum(m)-sum(n-1)); 42 43 return 0; 44 }
标签:判断 col 模拟 main 树状 sum bit break class
原文地址:https://www.cnblogs.com/stelayuri/p/12233148.html