-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathGIRLSNBS.cs
32 lines (29 loc) · 1 KB
/
GIRLSNBS.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using System;
// https://www.spoj.com/problems/GIRLSNBS/ #division
// Minimizes the max consecutive genders for some girls and boys sitting in a row.
public static class GIRLSNBS
{
public static int Solve(int girlCount, int boyCount)
{
int maxCount = Math.Max(girlCount, boyCount);
int minCount = Math.Min(girlCount, boyCount);
// This happens to work for the case where both are equal (including both zero).
// For normal cases where maxCount != minCount, note that minCount creates
// minCount + 1 slots to distribute maxCount kids (minCount - 1 interior, 2 exterior).
// Then round up.
return (int)Math.Ceiling((double)maxCount / (minCount + 1));
}
}
public static class Program
{
private static void Main()
{
int[] line;
while ((line = Array.ConvertAll(
Console.ReadLine().Split(), int.Parse))[0] != -1)
{
Console.WriteLine(
GIRLSNBS.Solve(line[0], line[1]));
}
}
}