static void Main(string[] args) { using (SpaceDelimReader sr = new SpaceDelimReader(args[0])) { int tst = sr.NextInt(); for (int cas = 1; cas <= tst; ++cas) { int h = sr.NextInt(); int w = sr.NextInt(); int R = sr.NextInt(); var points = sr.NextUEdge(R); bool[,] blocked = new bool[h + 10, w + 10]; points.Foreach(p => blocked[p.from, p.to] = true); int[,] dp = new int[h + 10, w + 10]; dp[1, 1] = 1; for (int i = 1; i <= h; ++i) { for (int j = 1; j <= w; ++j) { if (blocked[i, j] || dp[i, j] == 0) { continue; } dp[i + 2, j + 1] = (dp[i + 2, j + 1] + dp[i, j]) % 10007; dp[i + 1, j + 2] = (dp[i + 1, j + 2] + dp[i, j]) % 10007; } } Console.Write("Case #{0}: ", cas); Console.WriteLine(dp[h, w]); } } }
static void Main(string[] args) { using (SpaceDelimReader sr = new SpaceDelimReader(args[0])) { int tst = sr.NextInt(); for (int cas = 1; cas <= tst; ++cas) { int k = sr.NextInt(); int n = sr.NextInt(); var index = sr.NextInt(n); int[] a = new int[k]; for (int i = 0; i < k; ++i) { a[i] = i; } int[] res = new int[k]; for (int i = 0; i < k; ++i) { int ii = i % (k - i); res[a[ii]] = i + 1; a = remove(a, ii); } Console.Write("Case #{0}: ", cas); Console.WriteLine(string.Join(" ", index.Select(i => res[i - 1].ToString()).ToArray())); } } }
static void Main(string[] args) { using (SpaceDelimReader sr = new SpaceDelimReader(args[0])) { int tst = sr.NextInt(); for (int cas = 1; cas <= tst; ++cas) { int n = sr.NextInt(); long aa = sr.NextString().LongValue(); long b = sr.NextString().LongValue(); long c = sr.NextString().LongValue(); long d = sr.NextString().LongValue(); long x0 = sr.NextString().LongValue(); long y0 = sr.NextString().LongValue(); long M = sr.NextString().LongValue(); long[,] cnt = new long[3, 3]; cnt[x0 % 3, y0 % 3]++; for (int i = 1; i < n; ++i) { x0 = (x0 * aa + b) % M; y0 = (y0 * c + d) % M; cnt[x0 % 3, y0 % 3]++; } var pairs = Enumerable.Range(0, 3).SelectMany(i => Enumerable.Range(0, 3).Select(j => new { I = i, J = j })).ToArray(); long res = 0; for (int i = 0; i < pairs.Length; ++i) { res += Comb3(cnt[pairs[i].I, pairs[i].J]); for (int j = i + 1; j < pairs.Length; ++j) { int isu1 = pairs[i].I + pairs[j].I + pairs[i].I; int jsu1 = pairs[i].J + pairs[j].J + pairs[i].J; if (isu1 % 3 == 0 && jsu1 % 3 == 0) { res += cnt[pairs[j].I, pairs[j].J] * Comb2(cnt[pairs[i].I, pairs[i].J]); } int isu2 = pairs[i].I + pairs[j].I + pairs[j].I; int jsu2 = pairs[i].J + pairs[j].J + pairs[j].J; if (isu2 % 3 == 0 && jsu2 % 3 == 0) { res += cnt[pairs[i].I, pairs[i].J] * Comb2(cnt[pairs[j].I, pairs[j].J]); } for (int k = j + 1; k < pairs.Length; ++k) { int isu = pairs[i].I + pairs[j].I + pairs[k].I; int jsu = pairs[i].J + pairs[j].J + pairs[k].J; if (isu % 3 == 0 && jsu % 3 == 0) { res += cnt[pairs[i].I, pairs[i].J] * cnt[pairs[j].I, pairs[j].J] * cnt[pairs[k].I, pairs[k].J]; } } } } Console.Write("Case #{0}: ", cas); Console.WriteLine(res); } } }
static void Main(string[] args) { using (SpaceDelimReader sr = new SpaceDelimReader(args[0])) { int tst = sr.NextInt(); for (int cas = 1; cas <= tst; ++cas) { int n = sr.NextInt(); int m = sr.NextInt(); int a = sr.NextInt(); Console.Write("Case #{0}: ", cas); bool flag = true; int rx1 = -1; int ry1 = -1; int rx2 = -1; int ry2 = -1; for (int ix = 0; ix <= n && flag; ix++) { for (int iy = 0; iy <= m && flag; iy++) { for (int jx = 0; jx <= n && flag; jx++) { for (int jy = 0; jy <= m && flag; jy++) { int t1 = ix * jy - iy * jx; if (t1 < 0) { t1 = -t1; } if (t1 == a) { flag = false; rx1 = ix; ry1 = iy; rx2 = jx; ry2 = jy; } } } } } if (flag) { Console.WriteLine("IMPOSSIBLE"); } else { Console.WriteLine("0 0 " + rx1 + " " + ry1 + " " + rx2 + " " + ry2); } } } }
static void Main(string[] args) { using (SpaceDelimReader sr = new SpaceDelimReader(args[0])) { int tst = sr.NextInt(); for (int cas = 1; cas <= tst; ++cas) { int k = sr.NextInt(); string s = sr.NextString(); int res = k.AllPermutations().Select(p => GetSize(s, p)).Min(); Console.Write("Case #{0}: ", cas); Console.WriteLine(res); } } }
static void Main(string[] args) { using (SpaceDelimReader sr = new SpaceDelimReader(args[0])) { int tst = sr.NextInt(); for (int cas = 1; cas <= tst; ++cas) { int m = sr.NextInt(); int n = sr.NextInt(); string[] mat = sr.NextString(m); MaxMatching ob = new MaxMatching(mat, m, n); Console.Write("Case #{0}: ", cas); Console.WriteLine(ob.calc()); } } }
static void Main(string[] args) { using (SpaceDelimReader sr = new SpaceDelimReader(args[0])) { int tst = sr.NextInt(); for (int cas = 1; cas <= tst; ++cas) { Console.Write("Case #{0}: ", cas); int a = sr.NextInt(); int b = sr.NextInt(); int p = sr.NextInt(); NumberSet ob = new NumberSet(); Console.WriteLine(ob.Calc(a, b, p)); } } }
static void Main(string[] args) { using (SpaceDelimReader sr = new SpaceDelimReader(args[0])) { int tst = sr.NextInt(); for (int cas = 1; cas <= tst; ++cas) { int m = sr.NextInt(); int v = sr.NextInt(); int inter = (m - 1) / 2; int leaf = (m + 1) / 2; var ininter = sr.NextUEdge(inter); var g = ininter.Select(u => u.from).ToArray(); var c = ininter.Select(u => u.to).ToArray(); int[] lvalue = sr.NextInt(leaf); int[] cost0 = Enumerable.Repeat(100000, m).ToArray(); int[] cost1 = Enumerable.Repeat(100000, m).ToArray(); Doop[] func = new Doop[2]; func[0] = GetOr; func[1] = GetAnd; for (int i = inter; i < m; ++i) { int j = i - inter; if (lvalue[j] == 0) { cost0[i] = 0; } else { cost1[i] = 0; } } for (int i = inter - 1; i >= 0; --i) { int left0 = cost0[2 * i + 1]; int left1 = cost1[2 * i + 1]; int right0 = cost0[2 * i + 2]; int right1 = cost1[2 * i + 2]; var res1 = func[g[i]](left0, left1, right0, right1); cost0[i] = Math.Min(cost0[i], res1[0]); cost1[i] = Math.Min(cost1[i], res1[1]); if (c[i] == 1) { var res2 = func[1 - g[i]](left0, left1, right0, right1); cost0[i] = Math.Min(cost0[i], res2[0] + 1); cost1[i] = Math.Min(cost1[i], res2[1] + 1); } } int res = v == 0 ? cost0[0] : cost1[0]; Console.Write("Case #{0}: ", cas); if (res >= 20000) { Console.WriteLine("IMPOSSIBLE"); } else { Console.WriteLine(res); } } } }