hdu2864 Base B 思维&&进制题

“Base B”

 HDU - 2864 

AekdyCoin is so fond of math.He loves Number.He knows how to express a non-negative number into P base.Say,he knows that the number 71 in 2 Base is exactly “1000111”. But AekdyCoin doesn’t think it’s a proper way to express a number.AekdyCoin want to creat the “Base B”,whose digits’ value is not only equal or larger than A,but also smaller than A+B.For example,if A = 1,B = 5,then AekdyCoin could express number 65 in “Base 5” ,it is “225” definitely .(But Not “230”,0 is out of the range [1,5]!) 
AekdyCoin is quite exciting about his “invention”,now he hopes that you could write a program for him which could help him to express a number in “Base B”. 

Input

The input consists of several test cases. 

Every case has only three integers indicating N,A,B (0<=N<=10^9,0<=A<=100,2<=B<=100)

Output

For each case,you should output “Case x:” first where x is the case index.(x>=1). 
  Then output the expression in “Base B”,if the number of digit is more than one,you should split them with exactly one ‘ ‘. 
  We guarantee there is always a solution. 

Sample Input

65 1 5
15 0 2

Sample Output

Case 1: 2 2 5
Case 2: 1 1 1 1

        
  

Hint

Hint:
In case 1, 65 = 2 * 5^2 + 2 * 5 + 5 * 1,and all digits are in the range[1,5].

        
 

题意:要求转化为b进制 而且每个位数上的数不能小于a

题解:先把数转化为b进制然后 如果当前位数小于a 从前一位借1 然后当前位加b 

自己写一写就明白了

#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define PI acos(-1.0)
#define Max INT_MAX
#define Min INT_MIN
#define eps 1e-8
#define FRE freopen("a.txt","r",stdin)
#define maxn 10010
int arr[maxn];
int main(){
    int n,a,b,Case=0;
    while(scanf("%d%d%d",&n,&a,&b)!=EOF){
        int coun=0;
        while(n){
            arr[coun++]=n%b;
            n/=b;
        }
        for(int i=0;i<coun-1;i++){
            while(arr[i]<a){
                arr[i]+=b;
                arr[i+1]--;
            }
        }
        printf("Case %d:",++Case);
        for(int i=coun-1;i>=0;i--){
            printf(" %d",arr[i]);
        }printf("\n");
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值