protected void match_rearrange(XmlElement node, string type) { int count; int[][] array; XmlNodeList nodelist; XmlElement curnode; Random rand; IComparer cmp = new JaggedComparer(); object[] nodearray; Thread.Sleep(13); rand = new Random(); debugbox.Value += "In match_rearrange\n"; nodelist = node.GetElementsByTagName(type); count = nodelist.Count; array = new int[count][]; nodearray = new object[count]; for (int i = 0; i < count; i++) { array[i] = new int[2]; array[i][0] = (int)rand.Next(); array[i][1] = i; debugbox.Value += "Set entry[" + i + "] to pos: " + array[i][0] + "\n"; /* Always pop off the first one. */ curnode = (XmlElement)node.RemoveChild(nodelist[0]); nodearray[i] = (object)curnode; } for (int i = 0; i < count; i++) { debugbox.Value += "0: " + array[i][0] + " 1: " + array[i][1] + "\n"; } Array.Sort(array, cmp); for (int i = 0; i < count; i++) { debugbox.Value += "Selected entry[" + array[i][1] + "] in pos: " + i + "\n"; curnode = (XmlElement)nodearray[array[i][1]]; curnode.SetAttribute("position", (i + 1).ToString()); node.AppendChild(curnode); } }
protected void order_finisher(ref XmlElement node) { int count; int[][] array; XmlNodeList answerlist; XmlElement curnode; Random rand = new Random(); IComparer cmp = new JaggedComparer(); object[] nodearray; debugbox.Value += "In order finisher!\n"; answerlist = node.GetElementsByTagName("ANSWER"); count = answerlist.Count; array = new int[count][]; nodearray = new object[count]; for (int i = 0; i < count; i++) { array[i] = new int[2]; array[i][0] = (int)rand.Next(); array[i][1] = i; debugbox.Value += "Set entry[" + i + "] to pos: " + array[i][0] + "\n"; /* Always pop off the first one. */ curnode = (XmlElement)node.RemoveChild(answerlist[0]); nodearray[i] = (object)curnode; } for (int i = 0; i < count; i++) { debugbox.Value += "0: " + array[i][0] + " 1: " + array[i][0] + "\n"; } Array.Sort(array, cmp); for (int i = 0; i < count; i++) { debugbox.Value += "Selected entry[" + array[i][1] + "] in pos: " + i + "\n"; curnode = (XmlElement)nodearray[array[i][1]]; curnode.SetAttribute("position", (i + 1).ToString()); node.AppendChild(curnode); } }
public static int luckBalance(int k, List <List <int> > contests) { int luckBalance = 0; //int[][] arr = new int [contests.Count][]; //for (int i = 0; i < contests.Count; i++) //{ // arr[i] = new[] {contests[i][0], contests[i][1]}; //} var arr = contests.Select(x => x.ToArray()).ToArray(); JaggedComparer comp = new JaggedComparer(); Array.Sort(arr, comp); for (int i = 0; i < arr.Length; i++) { int luck = arr[i][0]; int importance = arr[i][1]; if (importance == 1 && k > 0) { k--; luckBalance += luck; } else if (importance == 1 && k == 0) { luckBalance -= luck; } if (importance == 0) { luckBalance += luck; } } return(luckBalance); }