Example #1
0
        public void Test1()
        {
            var maxMatching = new MaxMatching(new[] { "同", "一个", "世界", "梦想" });
            var words       = maxMatching.GetWords("同一个世界,同一个梦想").Distinct();

            Assert.Equal(new[] { "同", "一个", "世界", ",", "梦想" }, words);
        }
Example #2
0
 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());
         }
     }
 }
Example #3
0
File: 6.cs Project: qifanyyy/CLCDSA
    static void Main(string[] args)
    {
        string path    = @"C:\Users\Толик\Downloads\C-Large.in";
        string pathOut = path.Replace(".in", ".out");

        PushTestData(System.IO.File.ReadAllText(path));

        /*
         * PushTestData(@"3
         * 3
         * HYDROCARBON COMBUSTION
         * QUAIL BEHAVIOR
         * QUAIL COMBUSTION
         * 3
         * CODE JAM
         * SPACE JAM
         * PEARL JAM
         * 2
         * INTERGALACTIC PLANETARY
         * PLANETARY INTERGALACTIC");*/

        int t  = ReadInt();
        var sb = new StringBuilder();

        for (int k = 0; k < t; k++)
        {
            Console.WriteLine("TestId" + k);
            List <int> a = new List <int>();
            List <int> b = new List <int>();
            int        n = ReadInt();

            var d1      = new Dictionary <string, int>();
            var d2      = new Dictionary <string, int>();
            int nextId1 = 0;
            int nextId2 = 0;
            for (int i = 0; i < n; i++)
            {
                var a1 = new string(ReadStr());
                var a2 = new string(ReadStr());
                if (!d1.ContainsKey(a1))
                {
                    d1.Add(a1, nextId1++);
                }
                if (!d2.ContainsKey(a2))
                {
                    d2.Add(a2, nextId2++);
                }

                a.Add(d1[a1]);
                b.Add(d2[a2]);
            }

            /*
             * int nn = n+n+2;
             * int[,] map = new int[nn, nn];
             * for (int i = 2; i < nn; i++)
             *  for (int j = 2; j < nn; j++)
             *      if (i != j)
             *          map[i, j] = 1;
             *
             * var d = new Dictionary<string, int>();
             * int nextId = 2;
             * for (int i = 0; i < n; i++)
             * {
             *  if (!d.ContainsKey(a[i])) d.Add(a[i], nextId++);
             *  if (!d.ContainsKey(b[i])) d.Add(b[i], nextId++);
             *
             *  map[d[a[i]], d[b[i]]] = 0;
             *  map[0, d[a[i]]] = 1;
             *  map[d[b[i]], 1] = 1;
             * }
             *
             *
             *
             * MaxFlow.map = map;
             * MaxFlow.n = nextId;
             */

            var g = new List <int> [Math.Max(nextId1, nextId2)];
            for (int i = 0; i < g.Length; i++)
            {
                g[i] = new List <int>();
            }

            int extra = 0;
            for (int i = 0; i < a.Count; i++)
            {
                if (!g[a[i]].Contains(b[i]))
                {
                    g[a[i]].Add(b[i]);
                }
                else
                {
                    extra++;
                }
            }

            var maxArr = MaxMatching.BuildMaxMatching(g);
            int max    = maxArr.Count(x => x != -1);

            //bestDeep = int.MaxValue;
            //Go(a.Distinct().ToArray(), b.Distinct().ToArray(), new bool[nextId1], new bool[nextId2]);
            //max = bestDeep;

            int answer = nextId1 + nextId2 - max;

            //sb.AppendFormat("Case #{0}: {1}", k + 1, MaxFlow.GetMaxFlow());
            sb.AppendFormat("Case #{0}: {1}", k + 1, n - answer);
            sb.AppendLine();

            Console.WriteLine((k + 1) + " >>> " + (n - answer));
        }

        var str = sb.ToString();

        Console.WriteLine(str);
        System.IO.File.WriteAllText(pathOut, str);
        Console.WriteLine(pathOut);


        Console.WriteLine("ISSUE CHECK");
        var l1 = System.IO.File.ReadAllLines(pathOut);
        var l2 = System.IO.File.ReadAllLines(pathOut.Replace("5", "55"));

        for (int i = 0; i < l1.Length; i++)
        {
            if (l1[i] != l2[i])
            {
                Console.WriteLine("ISSUE");
                Console.WriteLine(l1[i]);
                Console.WriteLine(l2[i]);
            }
        }
    }