//配列のランダム並び替え void randomshuffle <T>(T[] a) { int len = a.Length; for (int i = 0; i < len - 1; i++) { swap(ref a[i], ref a[i + rnd.nextInt(len - i)]); } }
double greedy() { int go = 1; if (rnd.nextInt(2) == 0) { go = 0; } double pos = 0; double ret = 0; int pass = 0; int lastneedid = -1; bool[][] check = new bool[2][]; check[0] = new bool[num[0]]; check[1] = new bool[num[1]]; while (pass < 2) { double need = 0; int needid = -1; int targetnum = -1; if (targetlist[go].Count != 0) { targetnum = targetlist[go][rnd.nextInt(targetlist[go].Count)]; if (check[go][targetnum]) { targetnum = -1; } } if (targetnum == -1) { for (int i = 0; i < num[go]; i++) { if (check[go][i]) { continue; } double tempdist = Math.Abs(p[go][i] + s[go][i] * ret - pos); double temps = Y - Math.Abs(s[go][i]); double temptime = tempdist / temps; if (temptime > need) { need = temptime; needid = i; } check[go][i] = true; } } else { if (check[go][targetnum]) { continue; } double tempdist2 = Math.Abs(p[go][targetnum] + s[go][targetnum] * ret - pos); double temps2 = Y - Math.Abs(s[go][targetnum]); need = tempdist2 / temps2; check[go][targetnum] = true; needid = targetnum; for (int i = 0; i < num[go]; i++) { if (check[go][i]) { continue; } double tempdist = Math.Abs(p[go][i] + s[go][i] * ret - pos); double temps = Y - Math.Abs(s[go][i]); double temptime = tempdist / temps; if (temptime <= need + 1e-9) { check[go][i] = true; } } } if (need == 0) { pass++; } else { pass = 0; lastneedid = needid; ret += need; if (go == 0) { pos += need * Y; } else { pos -= need * Y; } } go ^= 1; } go ^= 1; if (!used[go, lastneedid]) { targetlist[go].Add(lastneedid); used[go, lastneedid] = true; } return(ret); }