public MovingPoint(CoordI p_cPos, CoordI p_cVel) { Pos = p_cPos; Vel = p_cVel; }
public FabricClaim(int p_iID, CoordI p_cTopL, CoordI p_cBotR) { id = p_iID; TopL = p_cTopL; BotR = p_cBotR; }
public static void Go_03() { var input = InputParser.GetLines("18", "03"); var claims = new Dictionary <int, FabricClaim>(); int id = 0; int xMax = 0; int yMax = 0; foreach (var line in input) { int indexAt = line.IndexOf('@'); int indexComma = line.IndexOf(','); int indexColon = line.IndexOf(':'); int indexX = line.IndexOf('x'); id = int.Parse(line.Substring(1, indexAt - 2)); int topX = int.Parse(line.Substring(indexAt + 2, indexComma - indexAt - 2)); int topY = int.Parse(line.Substring(indexComma + 1, indexColon - indexComma - 1)); int botX = topX + int.Parse(line.Substring(indexColon + 2, indexX - indexColon - 2)) - 1; int botY = topY + int.Parse(line.Substring(indexX + 1)) - 1; if (!claims.ContainsKey(id)) { claims.Add(id, new FabricClaim( id, new CoordI(topX, topY), new CoordI(botX, botY) )); xMax = Math.Max(xMax, botX); yMax = Math.Max(yMax, botY); } } int overlapCount = 0; var InsideCountByCords = new Dictionary <CoordI, List <int> >(); for (int y = 0; y <= yMax; y++) { for (int x = 0; x <= xMax; x++) { InsideCountByCords.Add(new CoordI(x, y), new List <int>()); } } foreach (var claim in claims.Values) { CoordI it = new CoordI(claim.TopL.x, claim.TopL.y); while (it.y <= claim.BotR.y) { while (it.x <= claim.BotR.x) { InsideCountByCords[it].Add(claim.id); if (InsideCountByCords[it].Count > 1) { claim.FoundOverlap = true; } if (InsideCountByCords[it].Count == 2) { claims[InsideCountByCords[it][0]].FoundOverlap = true; overlapCount++; } it.x++; } it.x = claim.TopL.x; it.y++; } } var clean = claims.Where(claim => !claim.Value.FoundOverlap).Select(claim => claim.Key).ToList(); int cleanId = clean.Last(); Console.WriteLine(overlapCount); Console.WriteLine(cleanId); }