Ejemplo n.º 1
0
Archivo: 8.cs Proyecto: qifanyyy/CLCDSA
        void run()
        {
            if (UseStandardIO)
            {
                _inputStream  = Console.In;
                _outputStream = Console.Out;
            }
            else
            {
                _inputStream  = File.OpenText(InputFile);
                _outputStream = File.CreateText(Path.Combine(new FileInfo(GetType().Assembly.Location).Directory.Parent.Parent.Parent.FullName, OutputFile));
            }

            int testsCount = int.Parse(_inputStream.ReadLine());

            C.Precalc();

            var solvers = new C[testsCount];

            for (int i = 0; i < testsCount; ++i)
            {
                solvers[i] = new C();
                solvers[i].ReadData();
            }

            int done = 0;

            if (UseMultiThreading)
            {
                solvers.AsParallel().WithDegreeOfParallelism(Math.Max(Environment.ProcessorCount, 2) - 1).ForAll(
                    solver => { solver.Solve(); Console.Title = (++done).ToString() + " of " + testsCount; });
            }
            else
            {
                for (int i = 0; i < testsCount; ++i)
                {
                    solvers[i].Solve();
                    Console.Title = (++done).ToString() + " of " + testsCount;
                }
            }
            for (int i = 0; i < testsCount; ++i)
            {
                Out.Write(string.Format("Case #{0}: ", i + 1));
                solvers[i].WriteAnswer();
            }
            Out.Flush();
            if (UseStandardIO)
            {
                Console.ReadLine();
            }
            else
            {
                Out.Close();
            }
        }
Ejemplo n.º 2
0
Archivo: 8.cs Proyecto: qifanyyy/CLCDSA
        void run()
        {
            if (IsTestingRun)
            {
                _inputStream  = File.OpenText("input.txt");
                _outputStream = Console.Out;
            }
            else
            {
                _inputStream  = File.OpenText(Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Downloads"), InputFile));
                _outputStream = File.CreateText(Path.Combine(new FileInfo(GetType().Assembly.Location).Directory.Parent.Parent.Parent.FullName, OutputFile));
            }

            Presolve();

            int testsCount = int.Parse(_inputStream.ReadLine());
            var solvers    = new Solution[testsCount];

            for (int i = 0; i < testsCount; ++i)
            {
                solvers[i] = new Solution();
                solvers[i].ReadData();
            }

            int done = 0;

            if (UseMultiThreading)
            {
                solvers.AsParallel().WithDegreeOfParallelism(Math.Max(Environment.ProcessorCount, 2)).ForAll(
                    solver => { solver.Solve(); Console.Title = (++done).ToString() + " of " + testsCount; });
            }
            else
            {
                for (int i = 0; i < testsCount; ++i)
                {
                    solvers[i].Solve();
                    Console.Title = (++done).ToString() + " of " + testsCount;
                }
            }
            for (int i = 0; i < testsCount; ++i)
            {
                Out.Write(string.Format("Case #{0}: ", i + 1));
                solvers[i].WriteAnswer();
            }
            Out.Flush();
            Out.Close();
            if (IsTestingRun)
            {
                Console.WriteLine("ALL DONE!");
                Console.ReadLine();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Closes the IO instance, stopping the ability to write and read.
        /// </summary>
        public void Close()
        {
            //Check
            if (!Open)
            {
                return;
            }

            //Close
            ms.Close();
            Out.Close();
            In.Close();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Closes the log
        /// </summary>
        /// <param name="suspend">supresses the 'Log closed message' (ready for a 'Resume()' to append more lines)</param>
        public static void Close(bool suspend)
        {
            if (suspend)
            {
                WriteLine("Log suspended");
            }
            else
            {
                WriteLine("Log closed normally");
            }

            Out.Flush();
            Out.Close();
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Closes the IO and any open streams.
 /// </summary>
 public virtual void Close()
 {
     if (Opened)
     {
         if (Stream != null)
         {
             Stream.Dispose();
         }
         if (In != null)
         {
             In.Close();
         }
         if (Out != null)
         {
             Out.Close();
         }
         Opened = false;
     }
 }
Ejemplo n.º 6
0
 public static void runnerMain()
 {
     if (stdIn)
     {
         In = new Reader(Console.OpenStandardInput());
     }
     else
     {
         In = new Reader(INPUT_FILE_NAME);
     }
     if (stdOut)
     {
         Out = new StreamWriter(Console.OpenStandardOutput());
     }
     else
     {
         Out = new StreamWriter(OUTPUT_FILE_NAME);
     }
     for (int i = 1; i <= NUM_OF_TEST_CASES; i++)
     {
         try {
             run(i);
         } catch (Exception e) {
             Out.WriteLine("Exception thrown on test case " + i);
             Out.WriteLine(e.StackTrace);
             Out.Flush();
             if (crash)
             {
                 throw new Exception();
             }
         }
         if (flush)
         {
             Out.Flush();
         }
     }
     In.Close();
     Out.Close();
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Close and release all resources used by this client.
        /// </summary>
        public void Dispose()
        {
            if (!Alive)
            {
                Out.Close();
                In.Close();
                return;
            }

            up.WaitOne();

            In.Close();
            Out.Close();

            up.Dispose();
            SignalHandler = new Dispatcher <Message>();

            if (OnClose != null)
            {
                OnClose();
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// 销毁游戏资源
 /// </summary>
 public void Dispose()
 {
     if (!mDisposed)
     {
         mDisposed = true;
         if (null != In)
         {
             In.Close();
             In = null;
         }
         if (null != Out)
         {
             Out.Close();
             Out = null;
         }
         if (null != Buffer)
         {
             Buffer.Close();
             Buffer.Dispose();
             Buffer = null;
         }
     }
 }