public Program(string inputFile, string outputFile)
        {
            io = new IOHelper(inputFile, outputFile, Encoding.Default);

            //n==6 -- 1 3 5 5 3 1 + 2 4 6 4 2 + 6
            //n==7 -- 1 3 5 7 5 3 1 + 2 4 6 6 4 2 + 7
            int n = io.NextInt();

            for (int i = 1; i <= n; i += 2)
            {
                io.Write(i + " ");
            }
            for (int i = n - (n % 2 == 0 ? 1 : 2); i >= 1; i -= 2)
            {
                io.Write(i + " ");
            }
            for (int i = 2; i <= n; i += 2)
            {
                io.Write(i + " ");
            }
            for (int i = n - (n % 2 == 0 ? 2 : 1); i >= 1; i -= 2)
            {
                io.Write(i + " ");
            }
            io.WriteLine(n);

            io.Dispose();
        }
        public Program(string inputFile, string outputFile)
        {
            io = new IOHelper(inputFile, outputFile, Encoding.Default);
            //直接思路:枚举1~m的lcm,对每个lcm枚举约数,然后约数的bin里都要,复杂度msqrt(m)
            //那么现在反转,枚举约数,再枚举这个数是哪些可能的lcm值的约数
            //根据调和级数公式,n/1+n/2+n/3+...n/n=nlogn

            int n=io.NextInt(),m = io.NextInt();
            List<int>[] bin = new List<int>[m + 1];
            for (int i = 0; i <= m; i++) bin[i] = new List<int>();
            for (int i = 1; i <= n; i++) {
                int x = io.NextInt();
                if (x <= m) bin[x].Add(i);
            }
            int[] cnt = new int[m + 1];
            for (int i = 1; i <= m; i++) {
                if (bin[i].Count == 0) continue;
                for (int j = i; j <= m; j += i) {
                    cnt[j] += bin[i].Count;
                }
            }
            int maxElement=cnt.Max();
            for (int i = 1; i <= m; i++) {
                if (cnt[i] == maxElement) {
                    io.WriteLine(i+" "+maxElement);
                    List<int> ans=new List<int>();
                    for (int j = 1; j <= Math.Sqrt(i); j++) {
                        if (i % j == 0) {
                            ans.AddRange(bin[j]);
                            if (j * j != i) ans.AddRange(bin[i / j]);
                        }
                    }
                    ans.Sort();
                    foreach (int k in ans) {
                        io.Write(k + " ");
                    }
                    break;
                }
            }

            io.Dispose();
        }
        public Program(string inputFile, string outputFile)
        {
            io = new IOHelper(inputFile, outputFile, Encoding.Default);

            //n==6 -- 1 3 5 5 3 1 + 2 4 6 4 2 + 6
            //n==7 -- 1 3 5 7 5 3 1 + 2 4 6 6 4 2 + 7
            int n = io.NextInt();
            for (int i = 1; i <= n; i += 2)
                io.Write(i + " ");
            for (int i = n - (n % 2 == 0 ? 1 : 2); i >= 1; i -= 2)
                io.Write(i + " ");
            for (int i = 2; i <= n; i += 2)
                io.Write(i + " ");
            for (int i = n - (n % 2 == 0 ? 2 : 1); i >= 1; i -= 2)
                io.Write(i + " ");
            io.WriteLine(n);

            io.Dispose();
        }
예제 #4
0
        public Program(string inputFile, string outputFile)
        {
            io = new IOHelper(inputFile, outputFile, Encoding.Default);
            //直接思路:枚举1~m的lcm,对每个lcm枚举约数,然后约数的bin里都要,复杂度msqrt(m)
            //那么现在反转,枚举约数,再枚举这个数是哪些可能的lcm值的约数
            //根据调和级数公式,n/1+n/2+n/3+...n/n=nlogn

            int n = io.NextInt(), m = io.NextInt();

            List <int>[] bin = new List <int> [m + 1];
            for (int i = 0; i <= m; i++)
            {
                bin[i] = new List <int>();
            }
            for (int i = 1; i <= n; i++)
            {
                int x = io.NextInt();
                if (x <= m)
                {
                    bin[x].Add(i);
                }
            }
            int[] cnt = new int[m + 1];
            for (int i = 1; i <= m; i++)
            {
                if (bin[i].Count == 0)
                {
                    continue;
                }
                for (int j = i; j <= m; j += i)
                {
                    cnt[j] += bin[i].Count;
                }
            }
            int maxElement = cnt.Max();

            for (int i = 1; i <= m; i++)
            {
                if (cnt[i] == maxElement)
                {
                    io.WriteLine(i + " " + maxElement);
                    List <int> ans = new List <int>();
                    for (int j = 1; j <= Math.Sqrt(i); j++)
                    {
                        if (i % j == 0)
                        {
                            ans.AddRange(bin[j]);
                            if (j * j != i)
                            {
                                ans.AddRange(bin[i / j]);
                            }
                        }
                    }
                    ans.Sort();
                    foreach (int k in ans)
                    {
                        io.Write(k + " ");
                    }
                    break;
                }
            }

            io.Dispose();
        }