Add tags

Add tags to the following comment

Pen4 2.8Ghz, WinXP, VS2008 Beta2

合計204226件

ファイルリダイレクト 23.109375秒でした。

出力にやたら時間がかかってます。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 自然数
{
    class Program
    {
        static void Main(string[] args)
        {
            DateTime prev = DateTime.Now;
            young(50);
            Console.WriteLine((DateTime.Now - prev).TotalSeconds);
        }

        static void young(int n)
        {
            List<int[]> youngList = new List<int[]>();
            Stack<int> stack = new Stack<int>();

            for( int i = n ; i > 0 ; --i )
                subYoung( youngList, stack, i, n-i );

            var x = from y in youngList
                    orderby y.Count() ascending
                    select y;

            foreach (int[] list in x)
            {
                foreach (int i in list)
                    Console.WriteLine( new string( '□', i ) );

                Console.WriteLine();
            }

            Console.WriteLine(youngList.Count());
        }

        static void subYoung( List<int[]> youngList, Stack<int> stack, int num, int zan )
        {
            stack.Push(num);

            if (zan == 0)
            {
                youngList.Add(stack.Reverse().ToArray());
            }
            else
            {
                for (int i = zan >= num ? num : zan; i > 0; --i)
                {
                    subYoung(youngList, stack, i, zan - i);
                }
            }

            stack.Pop();
        }
    }
}

Add tags

The input will be splited to tags with space.

Index

Feed

Other

Link

Pathtraq

loading...