UVa 11723 Numbering Roads (water ver.)

11723 - Numbering Roads

Time limit: 1.000 seconds

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2823

In my country, streets don’t 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:

1, 2, 1A, 2B
1, 2, 1A, 2C
3, 4, 3A, 4A
1, 2, 1B, 1C

Given the number of roads (R) 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).

查看本栏目更多精彩内容:http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

Sample Input        Output for Sample Input

8 5
100 2
0 0
Case 1: 1
Case 2: impossible

完整代码:

/*0.019s*/

#include<cstdio>  

int main()
{
    int r, n, cas = 0, temp;
    while (scanf("%d%d", &r, &n), r)
    {
        printf("Case %d: ", ++cas);
        temp = (r - 1) / n;
        if (temp <= 26) printf("%d\n", temp);
        else puts("impossible");
    }
    return 0;
}

以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索number
, names
, of
The
,以便于您获取更多的相关知识。

时间: 2025-01-26 17:35:06

UVa 11723 Numbering Roads (water ver.)的相关文章

UVa 11727 Cost Cutting (water ver.)

11727 - Cost Cutting Time limit: 1.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2827 Company XYZ have been badly hit by recession and is taking a lot of cost cutting

UVa 10300 Ecological Premium (water ver.)

10300 - Ecological PremiumTime limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=94&page=show_problem&problem=1241 German farmers are given a premium depending on the conditions at their far

UVa 488 Triangle Wave (water ver.)

488 - Triangle Wave Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=94&page=show_problem&problem=429 In this problem you are to generate a triangular wave form according to a specifie

UVa 10783 Odd Sum (water ver.)

10783 - Odd Sum Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=19&page=show_problem&problem=1724 Given a range [a, b], you are to find the summation of all the odd integers in this r

UVa 10079 Pizza Cutting (water ver.)

10079 - Pizza Cutting Time limit: 8.333 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1020 When someone calls Ivan lazy, he claims that it is his intelligence that helps

UVa 11332 Summing Digits (water ver.)

11332 - Summing Digits Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2307 For a positive integer n, let f(n) denote the sum of the digits of n when repr

UVa 12250 Language Detection (water ver.)

12250 - Language Detection Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=3402 English, Spanish, German, French, Italian and Russian are the 6 most promi

UVa 10252 Common Permutation (water ver.)

10252 - Common Permutation Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1193 Given two strings of lowercase letters, a and b, print the longest string

UVa 371 Ackermann Functions (water ver.)

371 - Ackermann Functions Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=307 An Ackermann function has the characteristic that the length of the sequence