Пример #1
0
        /// <summary>
        /// Button_4_Click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_4_Click(object sender, RoutedEventArgs e)
        {
            Debug.WriteLine("Button_4_Click");

            // Save list to Json
            LST.SaveListToJson <Data>(LST.OToL <Data>(Datas), "Datas.json");
        }
Пример #2
0
        /// <summary>
        /// Button_6_Click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_6_Click(object sender, RoutedEventArgs e)
        {
            Debug.WriteLine("Button_6_Click");

            // Load list from Json
            ReFillList(LST.LToO <Data>(LST.LoadListFromJson <Data>("Datas.json")));
        }
Пример #3
0
        /// <summary>
        /// Button_3_Click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_3_Click(object sender, RoutedEventArgs e)
        {
            Debug.WriteLine("Button_3_Click");

            // Save list to Xml
            LST.SaveListToXml <Data>(LST.OToL <Data>(Datas), "Datas.xml");
        }
Пример #4
0
    static object Solve()
    {
        var n = int.Parse(Console.ReadLine());
        var a = Read();

        var map = new CompressionHashMap(a);

        var lst = new LST <long, long>(map.Count,
                                       (x, y) => y == -1 ? x : x * y % M, -1,
                                       (x, y) => (x + y) % M, 0,
                                       (x, p, _, l) => x == 0 ? p + 1 : p * x % M);

        var r = 0L;

        foreach (var av in a)
        {
            var v = map[av];

            r += lst.Get(0, v + 1);
            r %= M;

            lst.Set(0, map.Count, 2);
            lst.Set(v, 0);
        }

        return(r);
    }
Пример #5
0
    static void Main()
    {
        Console.SetOut(new System.IO.StreamWriter(Console.OpenStandardOutput())
        {
            AutoFlush = false
        });
        var h = Read();
        var n = h[0];
        var a = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);

        var st = new LST <long, long>(n,
                                      (x, y) => x + y, 0,
                                      (x, y) => x + y, 0,
                                      (x, p, _, l) => p + x * l,
                                      a);

        for (int k = 0; k < h[1]; k++)
        {
            var q = Read();
            if (q[0] == 0)
            {
                st.Set(q[1], q[2]);
            }
            else
            {
                Console.WriteLine(st.Get(q[1], q[2]));
            }
        }
        Console.Out.Flush();
    }
Пример #6
0
        /// <summary>
        /// OpenMessageFileCommandCF
        /// </summary>
        private void OpenMessageFileCommandCF()
        {
            MdiChild tw = GetTopMDIWindow();

            if (tw == null)
            {
                return;
            }

            string messageFileName = LST.OpenFileDialog("Cmm Datein (*.cmm)|*.cmm;|Alle Dateien (*.*)|*.*\"");

            if (String.IsNullOrEmpty(messageFileName))
            {
                return;
            }

            ((UserControlTCPMDIChild)tw.Content).MessageList     = LST.LoadList <Message>(messageFileName);
            ((UserControlTCPMDIChild)tw.Content).MessageFileName = messageFileName;
            if (((UserControlTCPMDIChild)tw.Content).MessageList.Count > 0)
            {
                ((UserControlTCPMDIChild)tw.Content).FocusMessageIndex = 0;
                ((UserControlTCPMDIChild)tw.Content).FocusMessage      = ((UserControlTCPMDIChild)tw.Content).MessageList[0];
            }
            _logger.Info(String.Format("Lode MessageFile File {0}", messageFileName));
        }
Пример #7
0
    static void Main()
    {
        Console.SetOut(new System.IO.StreamWriter(Console.OpenStandardOutput())
        {
            AutoFlush = false
        });
        var h = Read();
        var n = h[0];

        var st = new LST <long, long>(n + 1,
                                      (x, y) => x + y, 0,
                                      (x, y) => x + y, 0,
                                      (x, p, _, l) => p + x * l);

        for (int k = 0; k < h[1]; k++)
        {
            var q = Read();
            if (q[0] == 0)
            {
                st.Set(q[1], q[2] + 1, q[3]);
            }
            else
            {
                Console.WriteLine(st.Get(q[1], q[2] + 1));
            }
        }
        Console.Out.Flush();
    }
Пример #8
0
    static void Main()
    {
        Console.SetOut(new System.IO.StreamWriter(Console.OpenStandardOutput())
        {
            AutoFlush = false
        });
        var h = Read();
        var n = h[0];

        var p = Powers(n - 1, 10);

        Array.Reverse(p);

        long[] unit = null;
        var    st   = new LST <int, long>(n,
                                          (x, y) => x == -1 ? y : x, -1,
                                          (x, y) => (x + y) % M, 0,
                                          (x, p, node, l) => x == -1 ? p : x * unit[node.i] % M,
                                          p);

        unit = (long[])st.a2.Clone();

        for (int k = 0; k < h[1]; k++)
        {
            var q = Read();
            st.Set(q[0] - 1, q[1], q[2]);
            Console.WriteLine(st.Get(0, n));
        }
        Console.Out.Flush();
    }
Пример #9
0
        /// <summary>
        /// LoadConnectionsCommandCF
        /// </summary>
        private void LoadConnectionsCommandCF()
        {
            double AcParentWindoHeight = ActualHeight;
            double AcParentWindoWidth  = ActualWidth;

            string configFileName = LST.OpenFileDialog("Cmc Datein (*.cmc)|*.cmc;|Alle Dateien (*.*)|*.*\"");

            if (String.IsNullOrEmpty(configFileName))
            {
                return;
            }

            RecentFileList.InsertFile(configFileName);
            Filepath      = configFileName;
            _IsFileLoaded = true;
            _IsFileNamed  = true;

            Connection newConnection = Connection.Load(configFileName);

            _logger.Info(String.Format("Load Connection File {0}", configFileName));

            MdiChild MdiChild = new MdiChild()
            {
                Title   = String.Format("{0} ( )", Path.GetFileName(configFileName)),
                Height  = (AcParentWindoHeight - MainMenu.ActualHeight - MainToolBar.ActualHeight) * 0.6,
                Width   = AcParentWindoWidth * 0.6,
                Content = new UserControlTCPMDIChild(newConnection, this)
            };

            ((UserControlTCPMDIChild)MdiChild.Content).TheMdiChild = MdiChild;
            MainMdiContainer.Children.Add(MdiChild);
        }
Пример #10
0
        /// <summary>
        /// SaveConnectionsCommandCF
        /// </summary>
        private void SaveConnectionsCommandCF()
        {
            MdiChild tw = GetTopMDIWindow();

            if (tw == null)
            {
                _logger.Info("Nothing to save!!");
                return;
            }

            string configFileName = LST.SaveFileDialog("Cmc Datein (*.cmc)|*.cmc;|Alle Dateien (*.*)|*.*\"");

            if (String.IsNullOrEmpty(configFileName))
            {
                return;
            }

            RecentFileList.InsertFile(configFileName);
            Filepath      = configFileName;
            _IsFileLoaded = true;
            _IsFileNamed  = true;

            ((UserControlTCPMDIChild)tw.Content).SetNewConnectionName(Path.GetFileName(configFileName));
            tw.Title = Path.GetFileName(configFileName);
            if (((UserControlTCPMDIChild)tw.Content).IsConnected)
            {
                tw.Title += " (!)";
            }
            else
            {
                tw.Title += " ( )";
            }
            Connection.Save(((UserControlTCPMDIChild)tw.Content).MyConnection, configFileName);
            _logger.Info(String.Format("Save Connection File {0}", configFileName));
        }
Пример #11
0
    static void Main()
    {
        var n  = int.Parse(Console.ReadLine());
        var rs = new int[n].Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()).ToArray();

        var xqs = rs.Select(r => new { x = r[0], d = 1, y1 = r[1], y2 = r[3] })
                  .Concat(rs.Select(r => new { x = r[2], d = -1, y1 = r[1], y2 = r[3] }))
                  .OrderBy(q => q.x);

        var st = new LST <int, int>(1000,
                                    (x, y) => x + y, 0,
                                    Math.Max, 0,
                                    (x, p, _, l) => p + x);
        int M = 0, xt = -1;

        foreach (var q in xqs)
        {
            if (xt < q.x)
            {
                M  = Math.Max(M, st.Get(0, 1000));
                xt = q.x;
            }

            st.Set(q.y1, q.y2, q.d);
        }
        Console.WriteLine(M);
    }
Пример #12
0
    static void Main()
    {
        Console.SetOut(new System.IO.StreamWriter(Console.OpenStandardOutput())
        {
            AutoFlush = false
        });
        var h = Read();
        var n = h[0];

        var st = new LST <int, int>(n,
                                    (x, y) => x == int.MinValue ? y : x, int.MinValue,
                                    Math.Min, int.MaxValue,
                                    (x, p, _, l) => x == int.MinValue ? p : x);

        for (int k = 0; k < h[1]; k++)
        {
            var q = Read();
            if (q[0] == 0)
            {
                st.Set(q[1], q[2] + 1, q[3]);
            }
            else
            {
                Console.WriteLine(st.Get(q[1], q[2] + 1));
            }
        }
        Console.Out.Flush();
    }
Пример #13
0
        /******************************/
        /*       Button Events        */
        /******************************/
        #region Button Events

        /// <summary>
        /// Button_1_Click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_1_Click(object sender, RoutedEventArgs e)
        {
            Debug.WriteLine("Button_1_Click");

            // Reload the default list
            ReFillList(LST.PopulateData());
        }
Пример #14
0
    static void Main()
    {
        var(n, qc) = Read2();
        var s  = Console.ReadLine().Select(c => c == '(' ? 1 : -1).ToArray();
        var qs = Array.ConvertAll(new bool[qc], _ => Read());

        var cs = new int[n + 1];

        for (int i = 0; i < n; ++i)
        {
            cs[i + 1] = cs[i] + s[i];
        }

        var st = new LST <int, int>(n + 1,
                                    (x, y) => x + y, 0,
                                    Math.Min, 1 << 30,
                                    (x, p, _, l) => x + p,
                                    cs);

        Console.SetOut(new System.IO.StreamWriter(Console.OpenStandardOutput())
        {
            AutoFlush = false
        });
        foreach (var q in qs)
        {
            var(l, r) = (q[1], q[2]);

            if (q[0] == 1)
            {
                if (s[l - 1] == s[r - 1])
                {
                    continue;
                }

                st.Set(l, r, s[l - 1] == 1 ? -2 : 2);
                s[l - 1] *= -1;
                s[r - 1] *= -1;
            }
            else
            {
                if ((r - l) % 2 == 0)
                {
                    WriteYesNo(false);
                    continue;
                }

                var vl = st.Get(l - 1);
                var vr = st.Get(r);
                if (vl != vr)
                {
                    WriteYesNo(false);
                    continue;
                }

                WriteYesNo(st.Get(l, r) >= vl);
            }
        }
        Console.Out.Flush();
    }
Пример #15
0
 public UFF(int N)
 {
     lsts       = new LST[N];
     mainsElems = new int[N];
     for (int i = 0; i < N; i++)
     {
         mainsElems[i] = i;
         lsts[i]       = new LST(i);
     }
 }
Пример #16
0
        /// <summary>
        /// Button_Save_Click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Save_Click(object sender, RoutedEventArgs e)
        {
            Debug.WriteLine("Button_Save_Click");

            LST.SaveList(LST.OToL <Course>(Courses), AppDomain.CurrentDomain.BaseDirectory + "Courses.xml");
            LST.SaveList(LST.OToL <Student>(Students), AppDomain.CurrentDomain.BaseDirectory + "Students.xml");
            LST.SaveList(LST.OToL <Binding>(Bindings), AppDomain.CurrentDomain.BaseDirectory + "Bindings.xml");

            Message = "We save Courses.xml, Students.xml and Bindings.xml";
        }
Пример #17
0
        /// <summary>
        /// Button_Load_Click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Load_Click(object sender, RoutedEventArgs e)
        {
            Debug.WriteLine("Button_Load_Click");

            Courses  = LST.LToO <Course>(LST.LoadList <Course>(AppDomain.CurrentDomain.BaseDirectory + "Courses.xml"));
            Students = LST.LToO <Student>(LST.LoadList <Student>(AppDomain.CurrentDomain.BaseDirectory + "Students.xml"));
            Bindings = LST.LToO <Binding>(LST.LoadList <Binding>(AppDomain.CurrentDomain.BaseDirectory + "Bindings.xml"));
            _bindingsWindow.Bindings = Bindings;

            Message = "We load Courses.xml, Students.xml and Bindings.xml";
        }
Пример #18
0
        /// <summary>
        /// Button_Reload_Click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Reload_Click(object sender, RoutedEventArgs e)
        {
            Debug.WriteLine("Button_Reload_Click");

            Courses  = LST.PopulateCourses();
            Students = LST.PopulateStudents();
            Bindings = LST.PopulateBindings();
            _bindingsWindow.Bindings = Bindings;

            InitGridColor();
        }
Пример #19
0
    static void Main()
    {
        var n  = int.Parse(Console.ReadLine());
        var c  = Read();
        var qc = int.Parse(Console.ReadLine());

        Func <int, int> map = i => i % 2 == 0 ? i / 2 : (n + i) / 2;

        var c2 = new int[n];

        for (int i = 0; i < n; i++)
        {
            c2[map(i)] = c[i];
        }

        var st = new LST <int, int>(n,
                                    (x, y) => x + y, 0,
                                    Math.Min, int.MaxValue,
                                    (x, p, _, l) => p + x,
                                    c2);

        var r = 0L;

        for (int k = 0; k < qc; k++)
        {
            var q = Read();
            if (q[0] == 1)
            {
                if (st.Get(map(q[1] - 1)) >= q[2])
                {
                    st.Set(map(q[1] - 1), -q[2]);
                    r += q[2];
                }
            }
            else if (q[0] == 2)
            {
                if (st.Get(0, n / 2) >= q[1])
                {
                    st.Set(0, n / 2, -q[1]);
                    r += (long)(n + 1) / 2 * q[1];
                }
            }
            else
            {
                if (st.Get(0, n) >= q[1])
                {
                    st.Set(0, n, -q[1]);
                    r += (long)n * q[1];
                }
            }
        }
        Console.WriteLine(r);
    }
Пример #20
0
        /// <summary>
        /// Constructor
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();
            DataContext = this;

            Courses  = LST.PopulateCourses();
            Students = LST.PopulateStudents();
            Bindings = LST.PopulateBindings();

            _bindingsWindow          = new BindingsWindow();
            _bindingsWindow.Bindings = Bindings;
        }
Пример #21
0
 /// <summary>
 /// Button_Click_Ok
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Button_Click_Ok(object sender, RoutedEventArgs e)
 {
     try
     {
         DialogResult = true;
         FocusMessage = new byte[HexEdit.Stream.Length];
         HexEdit.SubmitChanges();
         FocusMessage = HexEdit.Stream.ToArray();
     }
     catch (Exception ex)
     {
         _logger.Error(String.Format("Exception in {0} {1}", LST.GetCurrentMethod(), ex.Message));
     }
     Close();
 }
Пример #22
0
        /// <summary>
        /// Constructor
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();
            DataContext = this;

            Datas = LST.PopulateData();

            // Set Button ToolTips
            Button_1.ToolTip = "Button #1: reload the default list";
            Button_2.ToolTip = "Button #2: clear the list";
            Button_3.ToolTip = "Button #3: save the list/classes to Xml";
            Button_4.ToolTip = "Button #4: save the list/classes to Jason";
            Button_5.ToolTip = "Button #5: load the list from Xml";
            Button_6.ToolTip = "Button #6: load the list from Jason";
            Button_7.ToolTip = "Button #7: save just one single class to CDatas.json/CDatas.xml";
        }
Пример #23
0
            public void merge(int x, int y)
            {
                int  prX = mainsElems[x], prY = mainsElems[y];
                LST  lstFirst    = lsts[prX];
                LST  lstSecond   = lsts[prY];
                Node currentNode = lstFirst.head;

                while (currentNode != null)
                {
                    int i = currentNode.data;
                    mainsElems[i] = prY;
                    lstSecond.add(i);
                    currentNode = currentNode.next;
                }

                lsts[prX] = null;
            }
Пример #24
0
    static void Main()
    {
        Console.SetOut(new System.IO.StreamWriter(Console.OpenStandardOutput())
        {
            AutoFlush = false
        });
        var h = Read();
        var n = h[0];
        var a = Read();

        var st = new LST <int, int>(n,
                                    (x, y) => x == int.MinValue ? y : x, int.MinValue,
                                    Math.Max, int.MinValue,
                                    (x, p, _, l) => x == int.MinValue ? p : x,
                                    a);

        for (int k = 0; k < h[1]; k++)
        {
            var q = Read();
            if (q[0] == 1)
            {
                st.Set(q[1] - 1, q[2]);
            }
            else if (q[0] == 2)
            {
                Console.WriteLine(st.Get(q[1] - 1, q[2]));
            }
            else
            {
                Console.WriteLine(1 + st.Aggregate(q[1] - 1, n, n, (p, node, l) =>
                {
                    if (p < n || st.a2[node.i] < q[2])
                    {
                        return(p);
                    }
                    while (node.i < st.n2 >> 1)
                    {
                        node = q[2] <= st.a2[node.Child0.i] ? node.Child0 : node.Child1;
                    }
                    return(st.Original(node));
                }));
            }
        }
        Console.Out.Flush();
    }
Пример #25
0
    static void Main()
    {
        var h = Read();
        int n = h[0], k = h[1];
        var a = Array.ConvertAll(new int[n], _ => int.Parse(Console.ReadLine()));

        var st = new LST <int, int>(kM + 1,
                                    Math.Max, 0,
                                    Math.Max, 0,
                                    (x, p, _, l) => Math.Max(x, p));

        for (int i = 0; i < n; i++)
        {
            st.Set(Math.Max(0, a[i] - k), Math.Min(kM + 1, a[i] + k + 1), st.Get(a[i]) + 1);
        }

        Console.WriteLine(st.Get(0, kM + 1));
    }
Пример #26
0
        /// <summary>
        /// SaveMessageFileCommandCF
        /// </summary>
        private void SaveMessageFileCommandCF()
        {
            MdiChild tw = GetTopMDIWindow();

            if (tw == null)
            {
                _logger.Info("Nothing to save!!");
                return;
            }

            if (String.IsNullOrEmpty(((UserControlTCPMDIChild)tw.Content).MessageFileName) || ((UserControlTCPMDIChild)tw.Content).MessageFileName.Contains("New MessageFile"))
            {
                SaveMessageFileAsCommandCF();
                return;
            }

            LST.SaveList <Message>(((UserControlTCPMDIChild)tw.Content).MessageList, ((UserControlTCPMDIChild)tw.Content).MessageFileName);
            _logger.Info(String.Format("Save MessageFile File {0}", (((UserControlTCPMDIChild)tw.Content).MessageFileName)));
        }
Пример #27
0
        /******************************/
        /*      Menu Events          */
        /******************************/
        #region Menu Events

        #endregion
        /******************************/
        /*      Other Events          */
        /******************************/
        #region Other Events

        #endregion
        /******************************/
        /*      Other Functions       */
        /******************************/
        #region Other Functions

        /// <summary>
        /// ApplyMessageTabsContent
        /// </summary>
        /// <param name="i"></param>
        /// <returns></returns>
        private void ApplyMessagesFromTabsContent()
        {
            int i = 0;

            try
            {
                foreach (var t in TabItems)
                {
                    t.HexEditor.SubmitChanges();
                    MessagesToEdit[i].MessageName = t.Header;
                    MessagesToEdit[i].Content     = t.HexEditor.Stream.ToArray();
                    i++;
                }
                FocusMessage = MessagesToEdit[tabHexaEditors.SelectedIndex].Content;
            }
            catch (Exception ex)
            {
                _logger.Error(String.Format("Exception in {0} {1}", LST.GetCurrentMethod(), ex.Message));
            }
        }
Пример #28
0
        /// <summary>
        /// AddTabItem
        /// </summary>
        /// <param name="v"></param>
        private TabItem AddTabItem(Message m)
        {
            int count = TabItems.Count;

            TabItem tab = new TabItem();

            if (String.IsNullOrEmpty(m.MessageName))
            {
                m.MessageName = String.Format("Message {0}", count + 1);
            }
            tab.Header           = m.MessageName;
            tab.HexEditor        = new HexaEditor();
            tab.HexEditor.Width  = Double.NaN;
            tab.HexEditor.Height = Double.NaN;
            tab.HexEditor.Stream = new System.IO.MemoryStream(m.Content);
            TabItems.Add(tab);

            _logger.Trace(String.Format("AddTabItem in {0}", LST.GetCurrentMethod()));

            return(tab);
        }
Пример #29
0
        /// <summary>
        /// SaveMessageFileAsCommandCF
        /// </summary>
        private void SaveMessageFileAsCommandCF()
        {
            MdiChild tw = GetTopMDIWindow();

            if (tw == null)
            {
                _logger.Info("Nothing to save!!");
                return;
            }

            string messageFileName = LST.SaveFileDialog("Cmm Datein (*.cmm)|*.cmm;|Alle Dateien (*.*)|*.*\"");

            if (String.IsNullOrEmpty(messageFileName))
            {
                return;
            }

            ((UserControlTCPMDIChild)tw.Content).MessageFileName = messageFileName;
            LST.SaveList <Message>(((UserControlTCPMDIChild)tw.Content).MessageList, messageFileName);
            _logger.Info(String.Format("Save MessageFile File As {0}", messageFileName));
        }
Пример #30
0
    static void Main()
    {
        var(w, n) = Read2();
        var qs = Array.ConvertAll(new bool[n], _ => Read2());

        var st = new LST <int, int>(w,
                                    (x, y) => x == int.MinValue ? y : x, int.MinValue,
                                    Math.Max, int.MinValue,
                                    (x, p, _, l) => x == int.MinValue ? p : x,
                                    new int[w]);

        Console.SetOut(new System.IO.StreamWriter(Console.OpenStandardOutput())
        {
            AutoFlush = false
        });
        foreach (var(l, r) in qs)
        {
            var m = st.Get(l - 1, r) + 1;
            st.Set(l - 1, r, m);
            Console.WriteLine(m);
        }
        Console.Out.Flush();
    }