public void run2() { XRand r = new XRand(); cin = new Scanner(); int T = cin.nextInt(); init(); for (int i = 1; i <= T; i++) { Console.Write("Case #{0}: ", i); calc(); } }
void calc() { cin = new Scanner(); rnd = new XRand(); int N = cin.nextInt(); int[] A = cin.ArrayInt(N); //randomshuffle(A); int sum = A.Sum(); int MAX = 100000; bool[] dp = new bool[MAX]; dp[0] = true; for (int i = 0; i < N; i++) { bool[] nextdp = new bool[MAX]; for (int j = 0; j < MAX; j++) { if (!dp[j]) { continue; } int low = Math.Abs(j - A[i]); int high = j + A[i]; if (low < MAX) { nextdp[low] = true; } if (high < MAX) { nextdp[high] = true; } } dp = nextdp; } int ans = 0; for (int i = 0; i < MAX; i++) { if (dp[i]) { ans = (sum + i) / 2; break; } } Console.WriteLine(ans); }
public void run2() { XRand r = new XRand(); init(); cin = new Scanner(); int T = cin.nextInt(); int[] N = new int[T]; long[][] x = new long[T][]; long[][] y = new long[T][]; int[][] ret = new int[T][]; for (int i = 0; i < T; i++) { N[i] = cin.nextInt(); //N[i] = 3000; x[i] = new long[N[i]]; y[i] = new long[N[i]]; for (int j = 0; j < N[i]; j++) { x[i][j] = cin.nextInt(); y[i][j] = cin.nextInt(); //x[i][j] = r.nextInt(-1000000, 1000000); //y[i][j] = r.nextInt(-1000000, 1000000); } } Parallel.For(0, T, i => { ret[i] = new Nyan().run(N[i], x[i], y[i]); } ); for (int i = 0; i < T; i++) { Console.WriteLine("Case #{0}: ", i + 1); for (int j = 0; j < ret[i].Length; j++) { Console.WriteLine(ret[i][j]); } } }
void init() { rnd = new XRand(); }