示例#1
0
        static void ain(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput())
            {
                AutoFlush = false
            };

            SetOut(sw);

            Method(args);

            Out.Flush();
        }
示例#2
0
    static void Main()
    {
        SetIn(new StreamReader("C-large.in"));
        SetOut(new StreamWriter("c_out.txt"));
        int T = int.Parse(ReadLine());

        for (int i = 0; i < T; i++)
        {
            Write("Case #" + (i + 1) + ": ");
            new Program().Solve();
        }
        Out.Flush();
    }
示例#3
0
 public K()
 {
     SetOut(new StreamWriter(OpenStandardOutput())
     {
         AutoFlush = false
     });
     WriteLine(Solve());
     WriteLine(del.Count);
     foreach (var x in del)
     {
         WriteLine(x + 1);
     }
     Out.Flush();
 }
示例#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();
        }
示例#5
0
文件: 2.cs 项目: 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));
            }

            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(Environment.ProcessorCount).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();
            }
        }
示例#6
0
    static void Main()
    {
        SetIn(new StreamReader("B-small-attempt2.in"));
        SetOut(new StreamWriter("b_out_2.txt"));
        //SetOut(new StreamWriter(OpenStandardOutput()));
        int T = int.Parse(ReadLine());

        for (int i = 0; i < T; i++)
        {
            Write("Case #" + (i + 1) + ": ");
            new Program().Solve();
        }
        Out.Flush();
    }
示例#7
0
文件: 4.cs 项目: 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() );
			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();
			if ( UseStandardIO )
			{
				Console.ReadLine();
			}
			else
			{
				Out.Close();
			}
		}
示例#8
0
    public K()
    {
        SetOut(new StreamWriter(OpenStandardOutput())
        {
            AutoFlush = false
        });
        var I = G();

        N = I[0];
        M = I[1];
        Q = I[2];
        Solve();
        Out.Flush();
    }
示例#9
0
        private static void ApplicationAction()
        {
            Out.Flush();
            Stopwatch timer = null;

            if (Program.ShowTimerOutput)
            {
                Out.WriteLine("Routine starting");
                timer = Stopwatch.StartNew();
            }
            PassTime(TimeSpan.FromDays(365));


            double deltaA = AssetsValue - LastYearAssets, deltaL = LiabilitiesValue - LastYearLiabilities, deltaNW = (Cash + AssetsValue - LiabilitiesValue) - LastYearNetWorth;

            Out.WriteLine("\nTime is {1}={0:F0} years", (Now - Start).TotalDays / 365, 'Δ');
            Out.WriteLine("Cash in bank: {0}", FormatCash(Cash));
            Out.WriteLine("  Assets: {0}  ({1}{2}    {1}{3:F2}%)", FormatCash(AssetsValue).PadLeft(24, ' '), deltaA >= 0 ? "+" : "", FormatCash(deltaA), AssetsValue / LastYearAssets * 100 - 100);
            Out.WriteLine("  Liabilities: {0}  ({1}{2}    {1}{3:F2}%)", string.Format("-{0}", FormatCash(LiabilitiesValue)).PadLeft(19, ' '), deltaL >= 0 ? "+" : "", FormatCash(deltaL), LiabilitiesValue / LastYearLiabilities * 100 - 100);
            Out.WriteLine("\tNet worth: {0}  ({1}{2}    {1}{3:F2}%)", FormatCash(Cash + AssetsValue - LiabilitiesValue).PadLeft(19), deltaNW >= 0 ? "+" : "", FormatCash(deltaNW), (Cash + AssetsValue - LiabilitiesValue) / LastYearNetWorth * 100 - 100);
            Out.WriteLine();

            LastYearAssets      = AssetsValue != 0 ? AssetsValue : 1;
            LastYearLiabilities = LiabilitiesValue != 0 ? LiabilitiesValue : 1;
            LastYearNetWorth    = (Cash + AssetsValue - LiabilitiesValue) != 0 ? (Cash + AssetsValue - LiabilitiesValue) : 1;

            if (Program.ShowTimerOutput)
            {
                timer.Stop();
                Out.WriteLine("\t--> Routine executed in {0:F2} ms", timer.Elapsed.TotalMilliseconds);
            }

            Out.Flush();


            while (Cash >= 1)
            {
                if (HandleConsoleCommand())
                {
                    continue;
                }
                break;
            }


            Out.WriteLine("\n\n\nEND OF YEAR {0}\n-------------\n\n", (Now - Start).TotalDays / 365);
            Out.WriteLine("[Press enter to pass another year]");
            In.ReadLine();
        }
示例#10
0
        public static void Main(string[] args)
        {
            var sw = new StreamWriter(OpenStandardOutput())
            {
                AutoFlush = false
            };

            SetOut(sw);
            var a  = int.Parse(ReadLine());
            var bc = ReadLine().Split(' ').Select(int.Parse);

            WriteLine($"{a+bc.First() + bc.Last()} {ReadLine()}");

            Out.Flush();
        }
示例#11
0
    public static void Main()
    {
        var sw = new StreamWriter(OpenStandardOutput())
        {
            NewLine = "\n"
        };

#if DEBUG
        sw.AutoFlush = true;
#else
        sw.AutoFlush = false;
#endif
        SetOut(sw);
        Solve(new IO());
        Out.Flush();
    }
示例#12
0
        public static void Main(string[] args)
        {
            "===============Start of Solve================".WL();
            var stopwatch = new Stopwatch();
            var sw        = new StreamWriter(OpenStandardOutput())
            {
                AutoFlush = false
            };

            SetOut(sw);
            stopwatch.Start();
            Program.Calc.Solve();
            Out.Flush();
            stopwatch.Stop();
            "===============End of Solve================".WL();
            (stopwatch.ElapsedMilliseconds + " ms").WL();
            Out.Flush();
        }
示例#13
0
        public int PromptSelection(string promptOptions)
        {
            var prompts = promptOptions.Split('?');
            var prompt  = prompts.Length > 0 ? prompts[0] : string.Empty;
            var options = prompts.Length > 1 ? prompts[1].Split('/') : new string[1] {
                ""
            };

            ResetPageCount();
            if (!string.IsNullOrWhiteSpace(prompt))
            {
                Out.Write(prompt + "? ");
            }

            Out.Write("[" + string.Join('/', options) + "] ");

            Out.Flush();

            while (true)
            {
                try
                {
                    char ch = Char.ToLower(ReadChar());
                    int  i  = ch;
                    // Trace.Write(string.Format("[Debug:ReadChar=%{0}]", i));
                    if (ch == '\r' || ch == '\n')
                    {
                        return(0);
                    }
                    for (int choice = 0; choice < options.Length; choice++)
                    {
                        if (ch == Char.ToLower(options[choice][0]))
                        {
                            return(choice);
                        }
                    }
                }
                finally
                {
                    Out.Write('\r');
                    ClearToEOL();
                }
            }
        }
示例#14
0
    static void Main()
    {
        SetOut(new StreamWriter(OpenStandardOutput())
        {
            AutoFlush = false
        });
        var I = G;
        int N = I[0], M = I[1];
        var uf = new UnionFindTree(N);

        for (var i = 0; i < M; i++)
        {
            I = G;
            int a = I[0] - 1, b = I[1] - 1;
            uf.Unite(a, b);
        }
        var Q  = int.Parse(ReadLine());
        var sb = new StringBuilder();

        while (Q-- > 0)
        {
            I = G;
            int x = I[0] - 1, y = I[1] - 1, z = I[2], l = 0, r = M + 1;
            while (l < r)
            {
                var t = (l + r) / 2;
                int p = uf.Find(t, x), q = uf.Find(t, y), s = p == q?uf.GetSize(t, p) : uf.GetSize(t, p) + uf.GetSize(t, q);

                if (s >= z)
                {
                    r = t;
                }
                else
                {
                    l = t + 1;
                }
            }
            sb.AppendLine(l.ToString());
        }
        Write(sb);
        Out.Flush();
    }
示例#15
0
        /// <summary>
        /// Writes an entry to the log with time and date details automatically prepended.
        /// </summary>
        /// <param name="message">message to add to log</param>
        public static void WriteLine(string message)
        {
            //Console.Write(DateTime.Now.ToString("HH:mm:ss : "));
            //Console.WriteLine(message);


            if (IsLoggingToFile)
            {
                if (Out == null)
                {
                    return;
                }
                //	throw new Exception("error, Create() method must be called before any WriteLine() methods");
                Out.Write(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss "));

                Out.Write(" : ");
                Out.WriteLine(message);
                Out.Flush();
            }
        }
示例#16
0
        static void Method(string[] args)
        {
            int[] pqr = ReadInts();
            int   p   = pqr[0];
            int   q   = pqr[1];
            int   r   = pqr[2];
            int   min = Min(Min(p + q, p + r), q + r);

            var sw = new System.IO.StreamWriter(OpenStandardOutput())
            {
                AutoFlush = false
            };

            SetOut(sw);

            // Write output here
            WriteLine(min);

            Out.Flush();
        }
示例#17
0
        private CommandResultCode RemovePath(NetworkContext context, string pathName, string rootAddress)
        {
            IServiceAddress address;

            // If machine is null, we need to find the machine the path is on,
            if (rootAddress == null)
            {
                PathInfo pathInfo = context.Network.GetPathInfo(pathName);
                if (pathInfo == null)
                {
                    Out.WriteLine("The path '" + pathName + "' was not found.");
                    return(CommandResultCode.ExecutionFailed);
                }
                address = pathInfo.RootLeader;
            }
            else
            {
                address = ServiceAddresses.ParseString(rootAddress);
            }

            Out.WriteLine("Removing path " + pathName + " from root " + address);
            Out.Flush();

            MachineProfile p = context.Network.GetMachineProfile(address);

            if (p == null)
            {
                Out.WriteLine("Error: Machine was not found in the network schema.");
                return(CommandResultCode.ExecutionFailed);
            }
            if (!p.IsRoot)
            {
                Out.WriteLine("Error: Given machine is not a root.");
                return(CommandResultCode.ExecutionFailed);
            }

            // Remove the path,
            context.Network.RemovePathFromNetwork(pathName, address);
            Out.WriteLine("done.");
            return(CommandResultCode.Success);
        }
示例#18
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();
 }
示例#19
0
        // Puts the software buffer on the screen after clearing.
        public static void Flush()
        {
            string str = "";             // header + "\n";

            for (int i = 0; i < buf.Length; i++)
            {
                if (i == buf.Length - 1)
                {
                    str += padding + buf[i];
                }
                else
                {
                    str += padding + buf[i] + "\n";
                }
            }
            Console.Clear();
            BackgroundColor = ConsoleColor.White;
            ForegroundColor = ConsoleColor.Black;
            WriteLine(header);
            ResetColor();
            Out.Write(str);
            Out.Flush();
        }
示例#20
0
        private CommandResultCode ShowAnalytics(NetworkContext context)
        {
            context.Network.Refresh();

            MachineProfile[] profiles = context.Network.GetAllMachineProfiles();

            foreach (MachineProfile p in profiles)
            {
                Out.WriteLine(p.ServiceAddress.ToString());
                Out.Write("  ");
                if (p.IsError)
                {
                    Out.Write("Error: ");
                    Out.WriteLine(p.ErrorMessage);
                    return(CommandResultCode.ExecutionFailed);
                }

                long[] stats = context.Network.GetAnalyticsStats(p.ServiceAddress);
                if (stats.Length < 4)
                {
                    Out.WriteLine("Sorry, no analytics available yet.");
                    return(CommandResultCode.ExecutionFailed);
                }

                PrintStatItem(stats, 1);
                Out.Write(" ");
                PrintStatItem(stats, 5);
                Out.Write(" ");
                PrintStatItem(stats, 15);
                Out.WriteLine();

                Out.Flush();
            }

            Out.WriteLine();
            return(CommandResultCode.Success);
        }
示例#21
0
    static void Main()
    {
        SetOut(new StreamWriter(OpenStandardOutput())
        {
            AutoFlush = false
        });
        var I = G();
        int N = I[0], Q = I[1];
        var t = G().ToTree(0, N);

        for (var i = 0; i < Q; i++)
        {
            I = G();
            int a = I[1] - 1, b = I[2];
            if (I[0] == 1)
            {
                var x = t.Span(0, a);
                var y = t.Span(a, b).Add(I[3]);
                var z = t.Span(b, N);
                t = x.Join(y).Join(z);
            }
            else if (I[0] == 2)
            {
                int c = I[3] - 1, d = I[4];
                var x = t.Span(0, a);
                var y = t.Span(c, d);
                var z = t.Span(b, N);
                t = x.Join(y).Join(z);
            }
            else
            {
                WriteLine(t.Span(a, b).Sum());
            }
        }
        Out.Flush();
    }
示例#22
0
 static void Main()
 {
     //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
     new Program().solve();
     Out.Flush();
 }
示例#23
0
 public K()
 {
     // SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
     Solve();
     Out.Flush();
 }
示例#24
0
 public void Flush() => Out.Flush();
示例#25
0
        public string PromptEdit(string prompt = "", InputFlags flags = 0)
        {
            // WaitHandle.
            ResetPageCount();
            if (!string.IsNullOrWhiteSpace(prompt))
            {
                Out.Write(prompt);
            }
            Out.Flush();
            string line = string.Empty;
            char   c    = ' ';

            while (c != '\r')
            {
                c = ReadChar();
                // Trace.Write(string.Format("[Debug:ReadChar=%{0}]", (byte)c));
                switch (c)
                {
                case Esc:
                    c = ReadChar();
                    if (c == '~')     // DEL
                    {
                        if (line.Length > 0)
                        {
                            Out.Write("\b \b");
                            line = line.Remove(line.Length - 1, 1);
                        }
                    }
                    if (c == '[')
                    {
                        c = ReadChar();
                    }
                    break;

                case (char)127:
                case '\b':
                    // Backspace
                    if (line.Length > 0)
                    {
                        Out.Write("\b \b");
                        line = line.Remove(line.Length - 1, 1);
                    }
                    break;

                // Ignore non-printables
                case '\r':
                case (char)0:
                    continue;

                default:
                    line += c;
                    if (flags.HasFlag(InputFlags.Password))
                    {
                        Out.Write("*");
                    }
                    else
                    {
                        Out.Write(c);
                    }
                    break;
                }
                Out.Flush(); // interactive command editing
            }
            Out.WriteLine();
            Out.Flush();
            return(line);
        }
示例#26
0
 private void WriteClosing()
 {
     Out.Write(HTML_CLOSING);
     Out.Flush();
 }
示例#27
0
        static void Method(string[] args)
        {
            int n = ReadInt();

            long[][] xys  = new long[n][];
            char[]   dirs = new char[n];
            for (int i = 0; i < n; i++)
            {
                string[] ss = Read().Split();
                xys[i] = new long[2] {
                    int.Parse(ss[0]), int.Parse(ss[1])
                };
                dirs[i] = ss[2][0];
            }

            List <long>[] poses = new List <long> [6];
            for (int i = 0; i < 6; i++)
            {
                poses[i] = new List <long>();
            }
            for (int i = 0; i < n; i++)
            {
                switch (dirs[i])
                {
                case 'L':
                    poses[0].Add(xys[i][0]);
                    poses[5].Add(xys[i][1]);
                    break;

                case 'R':
                    poses[1].Add(xys[i][0]);
                    poses[5].Add(xys[i][1]);
                    break;

                case 'U':
                    poses[4].Add(xys[i][1]);
                    poses[2].Add(xys[i][0]);
                    break;

                case 'D':
                    poses[3].Add(xys[i][1]);
                    poses[2].Add(xys[i][0]);
                    break;
                }
            }
            for (int i = 0; i < 6; i++)
            {
                poses[i].Sort();
            }
            List <double> times = new List <double>();

            times.Add(0);
            for (int i = 0; i < 6; i += 3)
            {
                if (poses[i].Count > 0 && poses[i + 1].Count > 0)
                {
                    if (poses[i][poses[i].Count - 1]
                        > poses[i + 1][poses[i + 1].Count - 1])
                    {
                        times.Add((poses[i][poses[i].Count - 1]
                                   - poses[i + 1][poses[i + 1].Count - 1]) * 0.5);
                    }
                    if (poses[i][0] > poses[i + 1][0])
                    {
                        times.Add((poses[i][0]
                                   - poses[i + 1][0]) * 0.5);
                    }
                }
                if (poses[i].Count > 0 && poses[i + 2].Count > 0)
                {
                    if (poses[i][poses[i].Count - 1]
                        > poses[i + 2][poses[i + 2].Count - 1])
                    {
                        times.Add(poses[i][poses[i].Count - 1]
                                  - poses[i + 2][poses[i + 2].Count - 1]);
                    }
                    if (poses[i][0] > poses[i + 2][0])
                    {
                        times.Add(poses[i][0] - poses[i + 2][0]);
                    }
                }
                if (poses[i + 1].Count > 0 && poses[i + 2].Count > 0)
                {
                    if (poses[i + 1][poses[i + 1].Count - 1]
                        < poses[i + 2][poses[i + 2].Count - 1])
                    {
                        times.Add(poses[i + 2][poses[i + 2].Count - 1]
                                  - poses[i + 1][poses[i + 1].Count - 1]);
                    }
                    if (poses[i + 1][0] < poses[i + 2][0])
                    {
                        times.Add(poses[i + 2][0] - poses[i + 1][0]);
                    }
                }
            }
            double res = long.MaxValue;

            for (int i = 0; i < times.Count; i++)
            {
                double tmp = 1;
                for (int j = 0; j < 6; j += 3)
                {
                    double min = long.MaxValue;
                    double max = long.MinValue;
                    if (poses[j].Count > 0)
                    {
                        min = Min(min, poses[j][0] - times[i]);
                        max = Max(max,
                                  poses[j][poses[j].Count - 1] - times[i]);
                    }
                    if (poses[j + 1].Count > 0)
                    {
                        min = Min(min, poses[j + 1][0] + times[i]);
                        max = Max(max,
                                  poses[j + 1][poses[j + 1].Count - 1] + times[i]);
                    }
                    if (poses[j + 2].Count > 0)
                    {
                        min = Min(min, poses[j + 2][0]);
                        max = Max(max, poses[j + 2][poses[j + 2].Count - 1]);
                    }
                    tmp *= (max - min);
                }
                res = Min(res, tmp);
            }

            var sw = new System.IO.StreamWriter(OpenStandardOutput())
            {
                AutoFlush = false
            };

            SetOut(sw);

            // Write output here
            WriteLine(res);

            Out.Flush();
        }
示例#28
0
        static bool HandleConsoleCommand()
        {
            Out.WriteLine("\n\nBuy building of type {0}?", KeyNow);
            Console.WriteLine("\t \"'\" = buy 1, \";\" = buy with all spare cash, \"c\" = create custom building, \"t\"= set type, ENTER = no");
            string line = In.ReadLine();

            if (line == "'")
            {
                Asset type    = PresetAssets[KeyNow];
                Asset myAsset = type.Clone() as Asset;
                myAsset.Name = string.Format(myAsset.Name, Asset.ODO + 1);
                BuyAsset(myAsset);
            }
            else if (line.StartsWith(";"))
            {
                Asset  type = PresetAssets[KeyNow];
                double x    = 1000;
                while (Cash >= type.DownPayment)
                {
                    if ((int)type.DownPayment == 0)
                    {
                        if (x-- > 0)
                        {
                            continue;
                        }
                        else
                        {
                            break;
                        }
                    }
                    Asset myAsset = type.Clone() as Asset;
                    myAsset.Name = string.Format(myAsset.Name, Asset.ODO + 1);
                    BuyAsset(myAsset);
                }
            }
            else if (line == "c")
            {
                Asset newB = CreateAsset();
                if (newB == null)
                {
                    return(true);
                }

                BuyAsset(newB);
            }
            else if (line == "t")
            {
                Out.Write("Write asset key: ");
                line = In.ReadLine().ToUpper();
                Asset type;
                if (PresetAssets.TryGetValue(line, out type))
                {
                    Asset myAsset = type.Clone() as Asset;
                    myAsset.Name = string.Format(myAsset.Name, Asset.ODO + 1);
                    BuyAsset(myAsset);
                    KeyNow = line;
                }
                else
                {
                    Out.WriteLine("Type does not exist in iv.txt");
                }
            }
            else if (line == "sell")
            {
                Out.Write("Which asset do you want to sell? ");
                line = In.ReadLine();
                Asset soldAsset = Assets.FirstOrDefault(a => a.Name == line);
                if (soldAsset == null)
                {
                    Out.WriteLine("Cannot find an asset named {0}", line);
                }
                else
                {
                    double debt    = soldAsset.PrincipalDebt;
                    double value_  = soldAsset.Value;
                    double balance = -debt + value_;
                    Receive(value_, "Sold asset " + soldAsset.Name + " for " + FormatCash(value_));
                    //Pay(debt, "Paid off debt of " + FormatCash(debt));
                    PayTowardsPrincipal(debt, soldAsset);
                    Out.WriteLine("Balance: {0}", FormatCash(balance));

                    Assets.Remove(soldAsset);
                }
            }
            else if (line == "sell all")
            {
                Out.WriteLine("Are you sure?");
                if (In.ReadLine() == "yes")
                {
                    double totalBalance = 0;
                    foreach (var asset in Assets)
                    {
                        double debt    = asset.PrincipalDebt;
                        double value_  = asset.Value;
                        double balance = -debt + value_;
                        Receive(value_, "\nSold asset " + asset.Name + " for " + FormatCash(value_));
                        //Pay(debt, "Paid off debt of " + FormatCash(debt));
                        PayTowardsPrincipal(debt, asset);
                        if (Program.ShowTransactionsOutput)
                        {
                            Out.WriteLine("\tBalance: {0}", FormatCash(balance));
                        }
                        // TODO BALANCE VS PROFIT ?
                        totalBalance += balance;
                    }
                    Assets.Clear();
                    Out.WriteLine("\n\n\t Total Balance: {0}", FormatCash(totalBalance));
                }
            }
            else if (line == "sell range")
            {
                if (!SellRange())
                {
                    return(true);
                }
            }
            else if (line == "t?")
            {
                Out.WriteLine(IVTXT);
            }
            else if (line.StartsWith("pay"))
            {
                Out.WriteLine("Which asset?");
                string name = In.ReadLine();
                Asset  a    = Assets.FirstOrDefault(x => x.Name.EndsWith(name));
                if (a != null)
                {
                    double sum;
                    if (line == "pay full")
                    {
                        sum = a.PrincipalDebt;
                    }
                    else
                    {
                        Out.Write("Payment: ");
                        sum = ReadDouble();
                    }
                    PayTowardsPrincipal(sum, a);
                }
                else
                {
                    Out.WriteLine("Cannot find asset {0}", name);
                }
            }
            else if (line.StartsWith("is"))
            {
                Out.WriteLine("By how much?");

                double x = ReadDouble();
                if (x == 0)
                {
                    return(true);
                }
                ExpCat.OtherExp += x;
            }
            else if (line.StartsWith("assets"))
            {
                if (Assets.Count == 0)
                {
                    Out.WriteLine("No assets!");
                    return(true);
                }
                int breaker = 0;
                foreach (var asset in Assets)
                {
                    if (line != "assets verbose")
                    {
                        Out.WriteLine("{0}  = Valued at: {1}, original value: {2}, bought with {3}, total debt of {4}", asset.Name, FormatCash(asset.Value), FormatCash(asset.Cost), FormatCash(asset.DownPayment), FormatCash(asset.OutstandingDebt));
                    }
                    else
                    {
                        DescribeAsset(asset);
                        Out.WriteLine("\n");
                    }
                    if (++breaker % 40000 == 0)
                    {
                        Out.WriteLine("Operation seems time consuming.");
                        if (In.ReadLine() != "yes")
                        {
                            break;
                        }
                    }
                }
            }
            else if (line.StartsWith("asset1"))
            {
                try
                {
                    line = line.Substring(7);
                    if (string.IsNullOrWhiteSpace(line))
                    {
                        return(true);
                    }
                    Asset a = Assets.First(x => x.Name.EndsWith(line));
                    DescribeAsset(a);
                    Out.WriteLine();
                }
                catch (Exception e)
                {
                    Out.WriteLine(e.Message);
                }
            }
            else if (line == "assc")
            {
                Out.WriteLine("You own {0} assets.", Assets.Count);
            }
            else if (line == "cash")
            {
                Out.WriteLine("Cash available: {0}", FormatCash(Cash));
            }
            else if (line == "cout")
            {
                bool on = Program.ShowTransactionsOutput = !Program.ShowTransactionsOutput;
                Out.WriteLine("cout " + (on ? "ON" : "OFF"));
            }
            else if (line == "timer")
            {
                bool on = Program.ShowTimerOutput = !Program.ShowTimerOutput;
                Out.WriteLine("timer " + (on ? "ON" : "OFF"));
            }
            else if (line == "odo-reset")
            {
                Out.WriteLine("Warning! Resetting ODO can result in unexpected problems. Are you sure you want to continue?");
                if (In.ReadLine() == "yes")
                {
                    Asset.ODO = 0;
                    Out.WriteLine("ODO = 0.");
                }
            }
            else if (line == "hardmoney")
            {
                if (!HardMoneyTransactions.Any())
                {
                    Out.WriteLine("\tHardmoney is a function mainly used for hard money\n" +
                                  "\tlending simulation or for debugging purposes\n" +
                                  "\tTo see how it was used type \'showhardmoney\'." +
                                  "\nYou can now type the amount of money you want to receive.\n" +
                                  "If you want to pay it back simply input a negative sum.");
                }
                Out.Write("Amount? ");
                double sum = ReadDouble();
                Cash += sum;
                HardMoneyTransactions.Add(sum);
            }
            else if (line == "showhardmoney")
            {
                Out.WriteLine("Hardmoney log:");
                HardMoneyTransactions.ForEach(t => Out.WriteLine("\t{0}{1}", t < 0 ? "-" : " ", FormatCash(Math.Abs(t))));
                Out.WriteLine("\t--------\n\t== {0}", FormatCash(HardMoneyTransactions.Sum()));
                Out.WriteLine();
            }
            else if (line == "hardmoney handle")
            {
                double harddebt = HardMoneyTransactions.Sum();
                Cash -= harddebt;
                HardMoneyTransactions.Add(-harddebt);
            }
            else if (line == "help")
            {
                Out.WriteLine(Texts.help);
            }
            else if (line == "clear")
            {
                Console.Clear();
            }
            else if (line == "gc.collect()")
            {
                GC.Collect();
                Console.WriteLine("OK");
            }
            else if (line == "i-am-admin")
            {
                Program.AdminMode = true;
                Out.WriteLine("Admin mode on.");
            }
            else if (line == "admin-out")
            {
                Program.AdminMode = false;
                Out.WriteLine("Admin out of role.");
            }
            else if (line == "flush")
            {
                Out.Flush();
            }
            else if (line == "salarybumps")
            {
                SalaryBumps = !SalaryBumps;
                Console.WriteLine(SalaryBumps ? "ON" : "OFF");
            }
            else if (line == "exit-01")
            {
                Environment.Exit(1);
            }

            else if (line != "")
            {
                return(true);
            }
            else
            {
                return(false);
            }
            return(true);
        }
示例#29
0
        static void Method(string[] args)
        {
            int[] nmk = ReadInts();
            int   n   = nmk[0];
            int   m   = nmk[1];
            int   k   = nmk[2];

            long[] ps = ReadLongs();
            int[]  cs = ReadInts();
            long[] js = ReadLongs();

            List <Edge>[] graph = new List <Edge> [n];
            for (int i = 0; i < n; i++)
            {
                graph[i] = new List <Edge>();
            }

            for (int i = 0; i < m; i++)
            {
                int[] uvt = ReadInts();
                int   u   = uvt[0] - 1;
                int   v   = uvt[1] - 1;
                long  t   = uvt[2];
                graph[u].Add(new Edge(v, t));
                graph[v].Add(new Edge(u, t));
            }

            long[,] distances = new long[n, 2];
            for (int i = 0; i < n; i++)
            {
                distances[i, 0] = long.MaxValue;
                distances[i, 1] = long.MaxValue;
            }

            PriorityQueue <Pos> queue = new PriorityQueue <Pos>();

            queue.Enqueue(new Pos(1000000000, 0, 0));
            while (queue.Count() > 0)
            {
                Pos  posData  = queue.Dequeue();
                long distance = posData.distance;
                int  index    = posData.index;
                int  state    = posData.state;
                if (distances[index, state] <= distance)
                {
                    continue;
                }

                distances[index, state] = distance;
                if (state == 0)
                {
                    long nextDistance = distance - ps[index];
                    if (distances[index, 1] > nextDistance)
                    {
                        queue.Enqueue(new Pos(nextDistance, index, 1));
                    }
                }
                for (int i = 0; i < graph[index].Count; i++)
                {
                    int  to           = graph[index][i].to;
                    long nextDistance = distance + graph[index][i].distance;
                    if (distances[to, state] <= nextDistance)
                    {
                        continue;
                    }

                    queue.Enqueue(new Pos(nextDistance, to, state));
                }
            }

            long[] results = new long[k];
            for (int i = 0; i < k; i++)
            {
                results[i] = long.MinValue;
            }

            for (int i = 0; i < n; i++)
            {
                int  c   = cs[i] - 1;
                long val = -distances[i, 0] + 1000000000
                           - distances[i, 1] + 1000000000;
                val       += js[i];
                results[c] = Max(results[c], val);
            }


            var sw = new System.IO.StreamWriter(OpenStandardOutput())
            {
                AutoFlush = false
            };

            SetOut(sw);

            for (int i = 0; i < k; i++)
            {
                WriteLine(results[i]);
            }

            Out.Flush();
        }
示例#30
0
        static void Method(string[] args)
        {
            int[] nm = ReadInts();
            int   n  = nm[0];
            int   m  = nm[1];

            HashSet <int>[] graph = new HashSet <int> [n];
            for (int i = 0; i < n; i++)
            {
                graph[i] = new HashSet <int>();
            }

            for (int i = 0; i < m; i++)
            {
                int[] cd = ReadInts();
                int   c  = cd[0] - 1;
                int   d  = cd[1] - 1;
                graph[c].Add(d);
                graph[d].Add(c);
            }

            if (m % 2 == 1)
            {
                WriteLine(-1);
                return;
            }

            List <int>  poses = new List <int>();
            Queue <int> queue = new Queue <int>();

            bool[] visited = new bool[n];
            queue.Enqueue(0);
            while (queue.Count > 0)
            {
                int now = queue.Dequeue();
                if (visited[now])
                {
                    continue;
                }

                visited[now] = true;
                poses.Add(now);

                foreach (int to in graph[now])
                {
                    queue.Enqueue(to);
                }
            }

            List <int[]> res = new List <int[]>();

            int[] fromCnts = new int[n];
            for (int i = n - 1; i >= 0; i--)
            {
                int now = poses[i];
                if (fromCnts[now] % 2 == 1)
                {
                    int to = graph[now].First();
                    res.Add(new int[2] {
                        now, to
                    });
                    fromCnts[now]++;
                    graph[now].Remove(to);
                    graph[to].Remove(now);
                }

                int remain = (graph[now].Count / 2) * 2;
                for (int j = 0; j < remain; j++)
                {
                    int to = graph[now].First();
                    res.Add(new int[2] {
                        now, to
                    });
                    fromCnts[now]++;
                    graph[now].Remove(to);
                    graph[to].Remove(now);
                    queue.Enqueue(to);
                }

                if (graph[now].Count > 0)
                {
                    int to = graph[now].First();
                    res.Add(new int[2] {
                        to, now
                    });
                    fromCnts[to]++;
                    graph[now].Remove(to);
                    graph[to].Remove(now);
                    queue.Enqueue(to);
                }
            }

            var sw = new System.IO.StreamWriter(OpenStandardOutput())
            {
                AutoFlush = false
            };

            SetOut(sw);
            for (int i = 0; i < res.Count; i++)
            {
                WriteLine((res[i][0] + 1) + " " + (res[i][1] + 1));
            }

            Out.Flush();
        }