http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2609

A-Number and B-Number

 

Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^

题目描述

    Tom is very interested in number problem. Nowadays he is thinking of a problem about A-number and B-number.
    A-number is a positive integer whose decimal form contains 7 or it can be divided by 7. We can write down the first 10 A-number ( a[i] is the ith A-number) 
         {a[1]=7,a[2]=14,a[3]=17,a[4]=21,a[5]=27,a[6]=28,a[7]=35,a[8]=37,a[9]=42,a[10]=47};
    B-number is Sub-sequence of A-number which contains all A-number but a[k] ( that k is a  A-number.)  Like 35, is the 7th A-number and 7 is also an A-number so the 35 ( a[7] ) is not a B-number. We also can write down the first 10 B-number.

         {b[1]=7,b[2]=14,b[3]=17,b[4]=21,b[5]=27,b[6]=28,b[7]=37,b[8]=42,b[9]=47,b[10]=49};
    Now Given an integer N, please output the Nth B-number

输入

The input consists of multiple test cases.

For each test case, there will be a positive integer N as the description.

输出

For each test case, output an integer indicating the Nth B-number.

You can assume the result will be no more then 2^63-1.

示例输入

1
7
100

示例输出

7
37
470

提示

 

来源

 2013年山东省第四届ACM大学生程序设计竞赛

示例程序

 

 

分析:

一开始想到打表,结果超时咯,后来看了标程用了搜索写的,,,orz

 

超时代码:

 

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 using namespace std;
 5 bool fun(int n){
 6     if(n%7==0) return true;
 7     while(n) {
 8         if(n%10==7) return true;
 9         n/=10;
10     }
11     return false;
12 }
13 long long a[100000010];
14 long long  b[100010000];
15 int main(){
16     int i,c=0,cc=0;
17     //freopen("in.txt","r",stdin);
18     for(i=1;i<=100000000;i++)
19       if(fun(i)) a[++c]=i;
20     for(i=1;i<c;i++)
21        if(!fun(i))
22          { b[++cc]=a[i];}
23     long long  n;
24     while(cin>>n){
25         if(n>cc-1) cout<<"??";
26         else 
27         cout<<b[n]<<endl;}
28     return 0;
29 }
View Code

相关文章:

  • 2021-06-18
  • 2021-12-04
  • 2021-12-09
  • 2021-11-08
  • 2022-12-23
  • 2022-12-23
  • 2021-09-13
猜你喜欢
  • 2021-11-20
  • 2022-02-14
  • 2021-11-11
  • 2021-06-26
  • 2021-09-18
  • 2022-12-23
  • 2021-08-04
相关资源
相似解决方案