Example #1
0
File: 2.cs Project: qifanyyy/CLCDSA
        private void Go()
        {
            int T = m_io.ReadInt();

            for (int t = 0; t < T; t++)
            {
                int N = m_io.ReadInt();
                List <Tuple <char, int> > actions = new List <Tuple <char, int> >(N);
                for (int n = 0; n < N; n++)
                {
                    actions.Add(new Tuple <char, int>(m_io.ReadWord()[0], m_io.ReadInt()));
                }
                int otime = 0;
                int btime = 0;
                int opos  = 1;
                int bpos  = 1;
                foreach (var action in actions)
                {
                    if (action.Item1 == 'O')
                    {
                        UpdateRobot(action.Item2, ref opos, ref otime, bpos, btime);
                    }
                    else
                    {
                        UpdateRobot(action.Item2, ref bpos, ref btime, opos, otime);
                    }
                }

                m_io.WriteCase(Math.Max(otime, btime));
            }
        }
Example #2
0
File: 2.cs Project: qifanyyy/CLCDSA
        private void Go()
        {
            Dictionary <char, int> emptyTally = c_baseElements.ToDictionary(e => e, e => 0);

            int T = m_io.ReadInt();

            for (int t = 0; t < T; t++)
            {
                int C = m_io.ReadInt();
                Dictionary <string, char> combiners = new Dictionary <string, char>(C * 2);
                for (int c = 0; c < C; c++)
                {
                    string com = m_io.ReadWord();
                    combiners.Add(com.Substring(0, 2), com[2]);
                    if (com[1] != com[0])
                    {
                        combiners.Add(com[1].ToString() + com[0].ToString(), com[2]);
                    }
                }

                int D = m_io.ReadInt();
                HashSet <string> oposers = new HashSet <string>();
                for (int d = 0; d < D; d++)
                {
                    string opp = m_io.ReadWord();
                    oposers.Add(opp[0].ToString() + opp[1]);
                    oposers.Add(opp[1].ToString() + opp[0]);
                }

                int    N   = m_io.ReadInt();
                string seq = m_io.ReadWord();
                Dictionary <char, int> tally = new Dictionary <char, int>(emptyTally);
                List <char>            state = new List <char>(seq.Length);
                char last = '?';
                foreach (char next in seq)
                {
                    char toAdd = next;
                    char combined;
                    if (combiners.TryGetValue(last.ToString() + next, out combined))
                    {
                        toAdd = combined;
                    }

                    bool   flush    = false;
                    string toAddStr = toAdd.ToString();
                    foreach (string curact in tally.Where(kvp => kvp.Value > 0).Select(kvp => kvp.Key + toAddStr))
                    {
                        if (oposers.Contains(curact))
                        {
                            flush = true;
                            break;
                        }
                    }

                    if (flush)
                    {
                        tally = new Dictionary <char, int>(emptyTally);
                        state.Clear();
                        last = '?';
                    }
                    else
                    {
                        if (toAdd == next)
                        {
                            tally[toAdd]++;
                            state.Add(toAdd);
                        }
                        else
                        {
                            tally[last]--;
                            state[state.Count - 1] = toAdd;
                        }
                        last = toAdd;
                    }
                }


                m_io.WriteCase("[" + String.Join(", ", state) + "]");
            }
        }