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 being unique but that isn't always the case. The local government allocates some integers to name the roads and on many case the number of integers allocated is less t Hat the total number of roads. In "case" to "make" road names unique some single character suffixes are. So roads are named as 1, 2, 3, 1 A, 2B, 3C etc. Of course the number of suffixes is also always limited to (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, 1 A, 2B |
1, 2, 1 A, 2C |
3, 4, 3 A, 4 a |
1, 2, 1B, 1C |
Given the number of roads (R) and the numbers of integers allocated for naming (N), your job are to determine minimum how M Any different suffixes is required (of all possible namings) to name the streets assuming this no two streets can hav e 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's the total number of streets to being named and N denotes number integers allocated for naming.
Output
For each line of the input produce one line of output. This line contains the serial of output followed by a integer D which denotes the minimum number of suffixes required to Name the streets. If It isn't possible to name all the streets print "impossible" instead (without the quotes).
See more highlights of this column: 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 |
Complete code:
/*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 <=) printf ("%d\n", temp);
Else puts ("impossible");
}
return 0;
}