ZOJ Problem Set - 2965 Accurately Say "CocaCola"!  http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2965

 打表。求含有7或者是7的倍数的数。题目输入p,输出第一个连续出现p个满足条件的头。

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 #define mt(a,b) memset(a,b,sizeof(a))
 5 using namespace std;
 6 const int M=1024;
 7 bool vis[M];
 8 bool isgood(int x){
 9     while(x){
10         if(x%10==7) return true;
11         x/=10;
12     }
13     return false;
14 }
15 int ans[M];
16 int main(){
17     mt(vis,0);
18     for(int i=1;i<M;i++){
19         if(isgood(i)||!(i%7)){
20             vis[i]=true;
21         }
22     }
23     for(int i=1;i<=99;i++){
24         ans[i]=M;
25     }
26     int s=1,t=1;
27     for(int i=1;i<M;i++){
28         if(!vis[i]){
29             s=t=i;
30         }
31         else{
32             t++;
33             ans[t-s]=min(ans[t-s],s+1);
34         }
35     }
36     int n;
37     scanf("%d",&t);
38     while(t--){
39         scanf("%d",&n);
40         printf("%d\n",ans[n]);
41     }
42     return 0;
43 }
View Code

相关文章: