示例#1
0
    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();
        }
    }
示例#2
0
    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);
    }
示例#3
0
    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]);
            }
        }
    }
示例#4
0
文件: 0.cs 项目: qifanyyy/CLCDSA
 void init()
 {
     rnd = new XRand();
 }