static void Main(string[] args) { ILineReader reader; if (args.Length > 0) { reader = new FileLineReader(args[0]); } else { reader = new ConsoleLineReader(); } var input = reader.ReadLine().Split(' '); var N = int.Parse(input[0]); var I = int.Parse(input[1]); var pic = new ParticipantsInCountries(); while (I > 0) { I--; input = reader.ReadLine().Split(' '); var p1 = int.Parse(input[0]); var p2 = int.Parse(input[1]); pic.Add(p1, p2); } pic.Normalize(); var total = pic.countries.Sum(p => p.members.Count); var singleGroups = N - total; ComboGenerator cg = new ComboGenerator(pic.countries.Count, 2); long sum = 0; var combo = cg.Next(); while (combo != null) { sum += pic.countries[(int)combo[1] - 1].Count * pic.countries[(int)combo[2] - 1].Count; combo = cg.Next(); } var singleCombo = (long)(FactByFact(singleGroups, singleGroups - 2) / Fact(2)); var comboIntoCountry = pic.countries.Sum(p => p.members.Count * singleGroups); sum += singleCombo + comboIntoCountry; Console.WriteLine(sum); }
static void Main(string[] args) { ILineReader reader; if (args.Length > 0) { reader = new FileLineReader(args[0]); } else { reader = new ConsoleLineReader(); } var n = int.Parse(reader.ReadLine()); var c = Array.ConvertAll(reader.ReadLine().Split(' '), int.Parse); int jumps = 0; int current = 0; while (current < c.Length) { if (current + 2 < c.Length) { if (c[current + 2] != 1) { current += 2; } else { current += 1; } } else if (current + 1 < c.Length) { current += 1; } else { break; } jumps++; } Console.WriteLine(jumps); }
static void Main(string[] args) { ILineReader reader; if (args.Length > 0) { reader = new FileLineReader(args[0]); } else { reader = new ConsoleLineReader(); } var t = int.Parse(reader.ReadLine()); while (t > 0) { t--; var input = reader.ReadLine().Split(' '); var n = long.Parse(input[0]); var m = long.Parse(input[1]); var s = long.Parse(input[2]); long remainging = 0; if (n >= m) { remainging = m; } else { remainging = m % n; } long result = s + remainging - 1; if (result > n) { result = n - result; } Console.WriteLine(Math.Abs(result)); } //Console.ReadLine(); }
public static void Main(string[] args) { ILineReader reader; if (args.Length > 0) { reader = new FileLineReader(args[0]); } else { reader = new ConsoleLineReader(); } int testCases = int.Parse(reader.ReadLine()); List <string> result = new List <string>(); while (testCases > 0) { testCases--; string[] nodesNPaths = reader.ReadLine().Split(' '); int nodes = int.Parse(nodesNPaths[0]); int[,] graph = new int[nodes + 1, nodes + 1]; int paths = int.Parse(nodesNPaths[1]); while (paths > 0) { paths--; string[] path = reader.ReadLine().Split(' '); int n1 = int.Parse(path[0]); int n2 = int.Parse(path[1]); graph[n1, n2] = 6; graph[n2, n1] = 6; } int start = int.Parse(reader.ReadLine()); int[] visited = new int[nodes + 1]; int[] distance = new int[nodes + 1]; Queue q = new Queue(); int iteration = 1; q.Add(iteration, start); int currentItem = 0; do { currentItem = q.GetNext(iteration); if (currentItem == 0) { iteration++; currentItem = q.GetNext(iteration); if (currentItem == 0) { break; } } if (visited[currentItem] == 1) { continue; } for (int x = 1; x < nodes + 1; ++x) { if (x == currentItem) { continue; } if (visited[x] == 1) { continue; } if (graph[currentItem, x] != 0) { q.Add(iteration + 1, x); if (distance[x] == 0) { distance[x] = iteration * 6; } else if (distance[x] > iteration * 6) { distance[x] = iteration * 6; } } } visited[currentItem] = 1; }while (currentItem > 0); string output = String.Empty; for (int x = 1; x < distance.Length; ++x) { if (x == start) { continue; } if (x > 1) { output += " "; } if (distance[x] > 0) { output += distance[x].ToString(); } else { output += "-1"; } } result.Add(output.Trim()); } foreach (var s in result) { Console.WriteLine(s); } //Console.ReadLine(); }