public static string SolvePart2(string input) { var stringOps = input.Trim().Split(","); var ops = new Int32[stringOps.Length]; var i = 0; foreach (var stringOp in stringOps) { ops[i] = Int32.Parse(stringOp); i++; } int?result = null; for (var noun = 0; noun <= 50; noun++) { for (var verb = 0; verb <= 99; verb++) { var memory = (int[])ops.Clone(); memory[1] = noun; memory[2] = verb; var output = execute(memory); if (output == 19690720) { result = 100 * noun + verb; } } } return(result.ToString()); }
/// <summary> /// Zhang扩展细化 /// 貌似还不如不扩展.. 有点问题 /// </summary> /// <param name="data">二维数据</param> /// <param name="width">数据宽度</param> /// <param name="height">数据高度</param> protected void zhangExpandThinning(ref Byte[] data, Int32 width, Int32 height, out Byte[] result) { this.zhangThinning(ref data, width, height, out result); Int32[] tempData = new Int32[result.Length]; for (int i = 0; i < result.Length; i++) { if (result[i].Equals(0)) { tempData[i] = 1; } } Int32[] set; Queue <Int32> Dm = new Queue <int>(); Int32[] medianData = (Int32[])tempData.Clone(); #region 单像素细化 for (int i = 1; i < width - 1; i++) { for (int j = 1; j < height - 1; j++) { Int32 index = j * width + i; // 条件1 当前点为1 初始化标记flag = 0; if (medianData[index] == 0) { continue; } Int32 flag = 0; Queue <Int32> Sq = new Queue <int>(); set = getFilterWindow3x3(index, width, height, DirectType.Clock); do { // 条件a 搜索当前点4个斜对角如果有1则压入种子队列 for (int x = 2; x < set.Length; x += 2) { if (medianData[set[x]] == 1) { Sq.Enqueue(set[x]); } } if (Sq.Count > 0) { flag = 1; medianData[index] = 0; } // 条件b 如果flag为1将当前点十字方向为1点划入Dm同时置反 if (flag == 1) { for (int x = 1; x < set.Length; x += 2) { if (medianData[set[x]] == 1) { Dm.Enqueue(set[x]); medianData[set[x]] = (1 - medianData[set[x]]); } } } // 如果flag为0将当前点十字方向为1点划入种子队列 if (flag == 0) { for (int x = 1; x < set.Length; x += 2) { if (medianData[set[x]] == 1) { Sq.Enqueue(set[x]); } } } // 条件c flag置为0 删除当前种子点, 若种子队列非空, 则转条件a 否则继续下移连通点 flag = 0; if (Sq.Count > 0) { medianData[Sq.Dequeue()] = 0; } } while (Sq.Count > 0); } } while (Dm.Count > 0) { tempData[Dm.Dequeue()] = 0; } #endregion medianData = (Int32[])tempData.Clone(); #region 端点连接 for (int i = 1; i < width - 1; i++) { for (int j = 1; j < height - 1; j++) { Int32 index = j * width + i; // 条件1 当前点为1 if (medianData[index] == 0) { continue; } // 条件2 // 条件a 当前点8邻域求和 Int32 sum = 0; set = getFilterWindow3x3(index, width, height, DirectType.Clock); for (int x = 1; x < set.Length; x++) { sum += medianData[set[x]]; } if (sum != 2) { continue; } // 如果值为2 可能为断裂点或端点 if (sum == 2) { Int32[] tempSet; for (int x = 1; x < set.Length; x++) { if (medianData[set[x]] == 1) { tempSet = getFilterWindow3x3(set[x], width, height, DirectType.Clock); for (int y = 0; y < tempSet.Length; y++) { medianData[tempSet[y]] = 0; } } } Int32[] set5 = getFilterWindow(index, width, height, FilterWindowType.Rect5); sum = 0; for (int x = 1; x < set5.Length; x++) { sum += medianData[set5[x]]; } // 当前点为端点 if (sum == 0) { continue; } // 当前点为断裂短 if (sum > 0) { Int32 count = 1, sumx = i, sumy = j; for (int x = 1; x < set5.Length; x++) { if (medianData[set5[x]] == 0) { count++; sumy += set5[x] / width; sumx += set5[x] % width; } } tempData[(sumy / count) * width + (sumx / count)] = 1; } } } } #endregion for (int i = 0; i < result.Length; i++) { if (tempData[i] == 0) { result[i] = 255; } else { result[i] = 0; } } }
public void AddResult(ResultData r) { Boolean match = false; int indx = -1; foreach (MainResults MaRe in results) { //match = (MaRe.Latitude == r.Latitude && MaRe.Longitude == r.Longitude); match = (MaRe.OrganizationLocationID == r.OrganizationLocationID); if (match) { indx = results.IndexOf(MaRe); break; } } if (!match) { MainResults mr = new MainResults(); mr.TaxID = new String[] { r.TaxID }; mr.NPI = new String[] { r.NPI }; mr.PracticeName = r.PracticeName; mr.ProviderName = new String[] { r.ProviderName }; mr.PracticeRangeMin = String.Format("{0:c0}", decimal.Parse(r.RangeMin)); mr.RangeMin = new String[] { r.RangeMin }; mr.PracticeRangeMax = String.Format("{0:c0}", decimal.Parse(r.RangeMax)); mr.RangeMax = new String[] { r.RangeMax }; mr.PracticeYourCostMin = String.Format("{0:c0}", decimal.Parse(r.YourCostMin)); mr.YourCostMin = new String[] { r.YourCostMin }; mr.PracticeYourCostMax = String.Format("{0:c0}", decimal.Parse(r.YourCostMax)); mr.YourCostMax = new String[] { r.YourCostMax }; mr.Latitude = r.Latitude; mr.Longitude = r.Longitude; mr.OrganizationLocationID = r.OrganizationLocationID; mr.LocationAddress1 = r.LocationAddress1; mr.LocationCity = r.LocationCity; mr.LocationState = r.LocationState; mr.LocationZip = r.LocationZip; mr.Distance = r.Distance; mr.NumericDistance = r.NumericDistance; mr.PracticeFairPrice = r.FairPrice; mr.FairPrice = new Boolean[] { r.FairPrice }; mr.HGRecognized = new Int32[] { r.HGRecognized }; switch (r.HGRecognized) { case -1: mr.PracticeHGRecognized = "N/A"; break; case 0: mr.PracticeHGRecognized = "0/1 Physicians"; break; case 1: mr.PracticeHGRecognized = "1/1 Physicians"; break; default: mr.PracticeHGRecognized = "N/A"; break; } mr.PracticeAvgRating = r.HGOverallRating; mr.HGOverallRating = new Double[] { r.HGOverallRating }; mr.HGPatientCount = new int[] { r.HGPatientCount }; results.Add(mr); } else { MainResults mr = results[indx]; String[] s = new String[mr.TaxID.Length + 1]; mr.TaxID.CopyTo(s, 0); s[s.Length - 1] = r.TaxID; mr.TaxID = (String[])s.Clone(); mr.NPI.CopyTo(s, 0); s[s.Length - 1] = r.NPI; mr.NPI = (String[])s.Clone(); mr.ProviderName.CopyTo(s, 0); s[s.Length - 1] = r.ProviderName; mr.ProviderName = (String[])s.Clone(); mr.RangeMin.CopyTo(s, 0); s[s.Length - 1] = r.RangeMin; mr.RangeMin = (String[])s.Clone(); mr.PracticeRangeMin = String.Format("{0:c0}", ((double.Parse(mr.PracticeRangeMin.Replace("$", "")) + double.Parse(r.RangeMin)) / 2.0)); mr.RangeMax.CopyTo(s, 0); s[s.Length - 1] = r.RangeMax; mr.RangeMax = (String[])s.Clone(); mr.PracticeRangeMax = String.Format("{0:c0}", ((double.Parse(mr.PracticeRangeMax.Replace("$", "")) + double.Parse(r.RangeMax)) / 2.0)); mr.YourCostMin.CopyTo(s, 0); s[s.Length - 1] = r.YourCostMin; mr.YourCostMin = (String[])s.Clone(); mr.PracticeYourCostMin = String.Format("{0:c0}", ((double.Parse(mr.PracticeYourCostMin.Replace("$", "")) + double.Parse(r.YourCostMin)) / 2.0)); mr.YourCostMax.CopyTo(s, 0); s[s.Length - 1] = r.YourCostMax; mr.YourCostMax = (String[])s.Clone(); mr.PracticeYourCostMax = String.Format("{0:c0}", ((double.Parse(mr.PracticeYourCostMax.Replace("$", "")) + double.Parse(r.YourCostMax)) / 2.0)); Boolean[] b = new Boolean[mr.FairPrice.Length + 1]; mr.FairPrice.CopyTo(b, 0); b[b.Length - 1] = r.FairPrice; mr.FairPrice = (Boolean[])b.Clone(); if (!mr.PracticeFairPrice && r.FairPrice) { mr.PracticeFairPrice = r.FairPrice; } Int32[] i32 = new Int32[mr.HGRecognized.Length + 1]; mr.HGRecognized.CopyTo(i32, 0); i32[i32.Length - 1] = r.HGRecognized; mr.HGRecognized = (Int32[])i32.Clone(); switch (r.HGRecognized) { case -1: //Do Nothing break; case 0: if (mr.PracticeHGRecognized == "N/A") { mr.PracticeHGRecognized = "0/0 Physicians"; } String[] str0 = mr.PracticeHGRecognized.Replace("Physicians", "").Trim().Split('/'); mr.PracticeHGRecognized = String.Format("{0}/{1} Physicians", str0[0], (Convert.ToInt32(str0[1]) + 1).ToString()); break; case 1: if (mr.PracticeHGRecognized == "N/A") { mr.PracticeHGRecognized = "0/0 Physicians"; } String[] str1 = mr.PracticeHGRecognized.Replace("Physicians", "").Trim().Split('/'); mr.PracticeHGRecognized = String.Format("{0}/{1} Physicians", (Convert.ToInt32(str1[0]) + 1).ToString(), (Convert.ToInt32(str1[1]) + 1).ToString()); break; default: break; } Double[] d = new Double[mr.HGOverallRating.Length + 1]; mr.HGOverallRating.CopyTo(d, 0); d[d.Length - 1] = r.HGOverallRating; mr.HGOverallRating = (Double[])d.Clone(); mr.PracticeAvgRating = ((mr.PracticeAvgRating + r.HGOverallRating) / 2.0); int[] i = new int[mr.HGPatientCount.Length + 1]; mr.HGPatientCount.CopyTo(i, 0); i[i.Length - 1] = r.HGPatientCount; mr.HGPatientCount = (int[])i.Clone(); results[indx] = mr; } }