UVA11723 Numbering Roads【数学】

In my country, streets dont have names, each of them are just given a number as name. These numbers are supposed
to be unique but that is not always the case. The local government allocates some integers to name the roads and
in many case the number of integers allocated is less that the total number of roads. In that case to make road
names unique some single character suffixes are used. So roads are named as 1, 2, 3, 1A, 2B, 3C, etc. Of course the
number of suffixes is also always limited to 26 (A, B, . . . , Z). For example if there are 4 roads and 2 different integers
are allocated for naming then some possible assignments of names can be:
在这里插入图片描述
    Given the number of roads ® and the numbers of integers allocated for naming (N), your job is to determine minimum how many different suffixes will be required (of all possible namings) to name the streets assuming that no two streets can have same names.
在这里插入图片描述
Input
The input file can contain up to 10002 lines of inputs. Each line contains two integers R and N (0 < N, R < 10001). Here R is the total number of streets to be named and N denotes number integers allocated for naming.
Output
For each line of input produce one line of output. This line contains the serial of output followed by an integer D which denotes the minimum number of suffixes required to name the streets. If it is not possible to name all the streets print ‘impossible’ instead (without the quotes).
Sample Input
8 5
100 2
0 0
Sample Output
Case 1: 1
Case 2: impossible

问题链接UVA11723 Numbering Roads
问题简述:(略)
问题分析
    有R条街道和N个数字编号,数字前面可以有0-1个大写字母,问最少要几个字母才能给出R个不同的编号。
    如果有k个字母则n*(k+1)就能够生成的不同编号数。所以,(R-1)/N就是字母的个数。若超过26个字母则输出impossible。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* UVA11723 Numbering Roads */

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int r, n, caseno = 0;
    while(~scanf("%d%d", &r, &n) && (r || n)) {
        int tmp = (r - 1) / n;

        printf("Case %d: ", ++caseno);
        if(tmp <= 26) printf("%d\n", tmp);
        else printf("impossible\n");
    }

    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值