コード例 #1
0
ファイル: ProbCExcel.cs プロジェクト: stankiewiczm/contests
        internal void Output(Stall[] Stalls, int maxmin, Stall selected)
        {
            for (int i = 0, c = 1; i < Stalls.Length; i++, c++)
            {
                if (row == 1)
                {
                    ws.Column(c).Width = 6;
                }

                var stall = Stalls[i];

                //ws.Cells[row, c].Style.Fill.BackgroundColor.SetColor(stalls[i] ? Color.Red : Color.Green);
                ws.Cells[row, c].Value = String.Format("{0},{1}", stall.L, stall.R);

                if (stall.MinLR == maxmin)
                {
                    ws.Cells[row, c].Style.Fill.BackgroundColor.SetColor(Color.LightSteelBlue);
                }

                if (stall.Occupied)
                {
                    ws.Cells[row, c].Style.Fill.BackgroundColor.SetColor(Color.Red);
                }

                if (stall == selected)
                {
                    ws.Cells[row, c].Style.Fill.BackgroundColor.SetColor(Color.LightSeaGreen);
                }
            }

            row++;
        }
コード例 #2
0
        private void Simulate(bool[] stalls, int visitors)
        {
            var Stalls = new Stall[stalls.Length];

            Stalls[0] = new Stall {
                Occupied = true
            };
            Stalls[Stalls.Length - 1] = new Stall {
                Occupied = true
            };

            for (int i = 1; i < Stalls.Length - 1; i++)
            {
                Stalls[i] = new Stall {
                    I = i, L = i - 1, R = Stalls.Length - i - 2
                }
            }
            ;

            using (var excel = new ProbCExcel("probc.xlsx"))
            {
                while (visitors-- > 0)
                {
                    var maxmin = Stalls.Max(s => s.MinLR);
                    var maxmax = Stalls.Where(s => !s.Occupied && s.MinLR == maxmin)
                                 .OrderByDescending(s => s.MaxLR)
                                 .ThenBy(s => s.I)
                                 .First();

                    excel.Output(Stalls, maxmin, maxmax);

                    maxmax.L        = maxmax.R = 0;
                    maxmax.Occupied = true;

                    for (int l = maxmax.I - 1, o = 0; l >= 0; l--, o++)
                    {
                        if (Stalls[l].Occupied)
                        {
                            break;
                        }
                        else
                        {
                            Stalls[l].R = o;
                        }
                    }

                    for (int r = maxmax.I + 1, o = 0; r < Stalls.Length; r++, o++)
                    {
                        if (Stalls[r].Occupied)
                        {
                            break;
                        }
                        else
                        {
                            Stalls[r].L = o;
                        }
                    }

                    //excel.Output(Stalls, maxmin);
                }

                return;

                //while (visitors-- > 0)
                //{
                //    var maxlr = new int[stalls.Length];
                //    var minlr = new int[stalls.Length];
                //    for (int i = 1; i < stalls.Length - 1; i++)
                //    {
                //        if (stalls[i]) continue;

                //        int left = 0, right = 0;
                //        for (int l = i - 1; l >= 0 && !stalls[l]; l--, left++) ;
                //        for (int r = i + 1; r < stalls.Length && !stalls[r]; r++, right++) ;
                //        minlr[i] = Math.Min(left, right);
                //        maxlr[i] = Math.Max(left, right);
                //    }

                //    var maxmin = minlr.Max();

                //    var maxmax = 0;
                //    for (int i = 1; i < stalls.Length - 1; i++)
                //        if (minlr[i] == maxmin && maxlr[i] > maxmax)
                //            maxmax = maxlr[i];

                //    int selected = -1;

                //    for (int i = 1; i < stalls.Length; i++)
                //        if (!stalls[i] && minlr[i] == maxmin && maxmax == maxlr[i])
                //        {
                //            selected = i;
                //            stalls[i] = true;
                //            break;
                //        }

                //excel.Output(stalls, minlr, maxlr, maxmin, selected);
                //break;
                //}
            }
        }