洛谷 P1112 波浪数

题目描述

波浪数是在一对数字之间交替转换的数,如1212121,双重波浪数则是指在两种进制下都是波浪数的数,如十进制数191919是一个十进制下的波浪数,它对应的十一进制数121212也是一个波浪数,所以十进制数191919是一个双重波浪数。

类似的可以定义三重波浪数,三重波浪数在三种不同的进制中都是波浪数,甚至还有四重波浪数,如十进制300=606(七进制)=363(九进制)=454(八进制)=1A1(十三进制)…,你的任务就是在指定范围内找出双重、三重、四重波浪数。

输入输出格式

输入格式:

 

单独一行包含五个用空格隔开的十进制整数,前两个数表示进制的范围(2••32),第三与第四个数表示指定的范围(1••10000000),第五个数为2,3,4中的一个,表示要找的波浪数的重数。

 

输出格式:

 

从小到大以十进制形式输出指定范围内的指定重数的波浪数。一行输出一个数。

 

输入输出样例

输入样例#1:
10 11 190000 960000 2
输出样例#1:
191919
383838
575757
767676
959595

——————————————————————————————————我是分割线————————————————————————————————
 1 /*
 2     Problem:
 3     OJ:
 4     User:    S.B.S.
 5     Time:
 6     Memory:
 7     Length:
 8 */
 9 #include<iostream>
10 #include<cstdio>
11 #include<cstring>
12 #include<cmath>
13 #include<algorithm>
14 #include<queue>
15 #include<cstdlib>
16 #include<iomanip>
17 #include<cassert>
18 #include<climits>
19 #include<functional>
20 #include<bitset>
21 #include<vector>
22 #include<list>
23 #define F(i,j,k) for(int i=j;i<=k;++i)
24 #define M(a,b) memset(a,b,sizeof(a))
25 #define FF(i,j,k) for(int i=j;i>=k;i--)
26 #define maxn 10001
27 #define inf 0x3f3f3f3f
28 #define maxm 4001
29 #define mod 998244353
30 //#define LOCAL
31 using namespace std;
32 int read(){
33     int x=0,f=1;char ch=getchar();
34     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
35     while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
36     return x*f;
37 }
38 int n,m;
39 int x,y,a,b,k;
40 short hash[10000001];
41 inline int len(int x,int k)
42 {
43     int cnt=0;
44     while(x){
45         x/=k;
46         ++cnt;
47     }
48     return cnt;
49 }
50 inline int solve(int a,int b,int l,int k)
51 {
52     int x=0;
53     F(i,1,l){
54         if(i&1) x=x*k+a;
55         else x=x*k+b; 
56     }
57     return x;
58 }
59 inline void dfs(int k)
60 {
61     int l=len(a,k),r=len(b,k),u;
62     F(i,1,k-1)F(j,0,k-1){
63         if(i==j) continue;
64         F(u,l,r){
65             int num=solve(i,j,u,k);
66             if(num>=a&&num<=b) hash[num]++;
67         }
68     }
69 }
70 int main()
71 {
72     std::ios::sync_with_stdio(false);//cout<<setiosflags(ios::fixed)<<setprecision(1)<<y;
73     #ifdef LOCAL
74     freopen("data.in","r",stdin);
75     freopen("data.out","w",stdout);
76     #endif
77     cin>>x>>y>>a>>b>>k;
78     F(i,x,y) dfs(i);
79     F(i,a,b){
80         if(hash[i]==k) cout<<i<<endl;
81     }
82     return 0;
83 }
View Code

 

posted @ 2016-11-23 15:28  SBSOI  阅读(668)  评论(0编辑  收藏  举报