Example #1
0
        public void Solve(TextReader input, TextWriter output)
        {
            var scanner = new StreamTokenizer(input);
            int testNum = scanner.NextInt();

            foreach (int caseId in Enumerable.Range(1, testNum))
            {
                int n = scanner.NextInt();
                int m = scanner.NextInt();
                var s = new HashSet <string>();
                s.Add("");
                for (int i = 0; i < n; i++)
                {
                    AddPath(s, scanner.Next());
                }
                int answer = 0;
                for (int i = 0; i < m; i++)
                {
                    answer += AddPath(s, scanner.Next());
                }
                output.WriteLine("Case #{0}: {1}", caseId, answer);
            }
            output.Close();
        }
Example #2
0
        public void Solve(TextReader input, TextWriter output)
        {
            var scanner = new StreamTokenizer(input);
            int testNum = scanner.NextInt();

            foreach (int caseId in Enumerable.Range(1, testNum))
            {
                int n = scanner.NextInt();
                var t = Enumerable.Range(0, n).Select(i => BigInteger.Parse(scanner.Next())).ToArray();
                var m = t.Min();
                var d = t.Select(v => v - m).Where(v => v > 0).Aggregate(BigInteger.Zero, (s, v) => GCD(v, s));
                m %= d;
                output.WriteLine("Case #{0}: {1}", caseId, m > 0 ? d - m : 0);
            }
            output.Close();
        }
Example #3
0
        public void Solve(TextReader input, TextWriter output)
        {
            var scanner = new StreamTokenizer(input);
            int testNum = scanner.NextInt();

            foreach (int caseId in Enumerable.Range(1, testNum))
            {
                int      n     = scanner.NextInt();
                string[] match = new string[n];
                int[]    win   = new int[n];
                int[]    total = new int[n];
                double[] wp    = new double[n];
                double[] owp   = new double[n];
                double[] oowp  = new double[n];
                double[] rpi   = new double[n];
                for (int i = 0; i < n; i++)
                {
                    match[i] = scanner.Next();
                    win[i]   = match[i].Count(c => c == '1');
                    total[i] = match[i].Count(c => c != '.');
                    wp[i]    = (double)win[i] / total[i];
                }
                for (int i = 0; i < n; i++)
                {
                    double sum = 0;
                    for (int j = 0; j < n; j++)
                    {
                        if (match[i][j] != '.')
                        {
                            if (match[j][i] == '1')
                            {
                                sum += (double)(win[j] - 1) / (total[j] - 1);
                            }
                            else
                            {
                                sum += (double)win[j] / (total[j] - 1);
                            }
                        }
                    }
                    owp[i] = sum / total[i];
                }
                for (int i = 0; i < n; i++)
                {
                    double sum = 0;
                    for (int j = 0; j < n; j++)
                    {
                        if (match[i][j] != '.')
                        {
                            sum += owp[j];
                        }
                    }
                    oowp[i] = sum / total[i];
                }
                output.WriteLine("Case #{0}:", caseId);
                for (int i = 0; i < n; i++)
                {
                    rpi[i] = 0.25 * wp[i] + 0.5 * owp[i] + 0.25 * oowp[i];
                    output.WriteLine("{0}", rpi[i]);
                }
            }
            output.Close();
        }
Example #4
0
File: 2.cs Project: qifanyyy/CLCDSA
        public void Solve(TextReader input, TextWriter output)
        {
            var scanner = new StreamTokenizer(input);
            int testNum = scanner.NextInt();

            foreach (int caseId in Enumerable.Range(1, testNum))
            {
                int r = scanner.NextInt();
                int c = scanner.NextInt();
                int d = scanner.NextInt();

                int[,] w  = new int[r + 1, c + 1];
                int[,] xw = new int[r + 1, c + 1];
                int[,] yw = new int[r + 1, c + 1];
                int[,] sw = new int[r + 1, c + 1];
                int[,] sx = new int[r + 1, c + 1];
                int[,] sy = new int[r + 1, c + 1];

                for (int i = 0; i < r; i++)
                {
                    string s = scanner.Next();
                    for (int j = 0; j < c; j++)
                    {
                        w[i + 1, j + 1]  = s[j] - '0';
                        sw[i + 1, j + 1] = w[i + 1, j + 1];
                        xw[i + 1, j + 1] = w[i + 1, j + 1] * (i + 1);
                        yw[i + 1, j + 1] = w[i + 1, j + 1] * (j + 1);
                        sx[i + 1, j + 1] = xw[i + 1, j + 1];
                        sy[i + 1, j + 1] = yw[i + 1, j + 1];
                    }
                }
                for (int i = 0; i < r; i++)
                {
                    for (int j = 0; j < c; j++)
                    {
                        sw[i + 1, j + 1] += sw[i + 1, j] + sw[i, j + 1] - sw[i, j];
                        sx[i + 1, j + 1] += sx[i + 1, j] + sx[i, j + 1] - sx[i, j];
                        sy[i + 1, j + 1] += sy[i + 1, j] + sy[i, j + 1] - sy[i, j];
                    }
                }

                int answer = -1;
                for (int i = 0; i < r; i++)
                {
                    for (int j = 0; j < c; j++)
                    {
                        for (int k = 3; k <= Math.Min(r - i, c - j); k++)
                        {
                            int tx = getShape(xw, sx, i + 1, j + 1, i + k, j + k);
                            int ty = getShape(yw, sy, i + 1, j + 1, i + k, j + k);
                            int tw = getShape(w, sw, i + 1, j + 1, i + k, j + k);
                            if (2 * tx == tw * (2 * i + 1 + k) && 2 * ty == tw * (2 * j + 1 + k))
                            {
                                answer = Math.Max(answer, k);
                            }
                        }
                    }
                }

                if (answer == -1)
                {
                    output.WriteLine("Case #{0}: IMPOSSIBLE", caseId);
                }
                else
                {
                    output.WriteLine("Case #{0}: {1}", caseId, answer);
                }
            }
            output.Close();
        }
Example #5
0
        /// <summary>
        /// Read a *.dem file
        /// </summary>
        /// <param name="filename"></param>
        public void Read(string filename)
        {
            StreamReader reader = new StreamReader(filename);

            char[] buffer = new char[1024]; // size of A Record
            reader.Read(buffer, 0, 1024);

            _mARecord                        = new ARecord();
            _mARecord.file_name              = ParseString(buffer, 0, 40).ToCharArray();
            _mARecord.free_text_format       = ParseString(buffer, 40, 40).ToCharArray();
            _mARecord.SE_geographic_corner_S = ParseString(buffer, 109, 13).ToCharArray();
            _mARecord.SE_geographic_corner_E = ParseString(buffer, 122, 13).ToCharArray();
            _mARecord.process_code           = buffer[135];
            _mARecord.origin_code            = ParseString(buffer, 140, 4).ToCharArray();
            _mARecord.dem_level_code         = ParseInt(buffer, 144);
            _mARecord.elevation_pattern      = ParseInt(buffer, 150);
            _mARecord.ground_ref_system      = ParseInt(buffer, 156);
            _mARecord.ground_ref_zone        = ParseInt(buffer, 162);
            for (int i = 0; i < 15; i++)
            {
                _mARecord.projection[0] = ParseDouble(buffer, 168 + i * 24);
            }
            _mARecord.ground_unit        = ParseInt(buffer, 528);
            _mARecord.elevation_unit     = ParseInt(buffer, 534);
            _mARecord.side_count         = ParseInt(buffer, 540);
            _mARecord.sw_coord[0]        = (float)ParseDouble(buffer, 546); // UTM grid (measured in meters)
            _mARecord.sw_coord[1]        = (float)ParseDouble(buffer, 570);
            _mARecord.nw_coord[0]        = (float)ParseDouble(buffer, 594);
            _mARecord.nw_coord[1]        = (float)ParseDouble(buffer, 618);
            _mARecord.ne_coord[0]        = (float)ParseDouble(buffer, 642);
            _mARecord.ne_coord[1]        = (float)ParseDouble(buffer, 666);
            _mARecord.se_coord[0]        = (float)ParseDouble(buffer, 690);
            _mARecord.se_coord[1]        = (float)ParseDouble(buffer, 714);
            _mARecord.elevation_min      = ParseDouble(buffer, 738);
            _mARecord.elevation_max      = ParseDouble(buffer, 762);
            _mARecord.ccw_angle          = ParseDouble(buffer, 786);
            _mARecord.elevation_accuracy = ParseInt(buffer, 810);
            _mARecord.xyz_resolution[0]  = ParseFloat(buffer, 816);
            _mARecord.xyz_resolution[1]  = ParseFloat(buffer, 828);
            _mARecord.xyz_resolution[2]  = ParseFloat(buffer, 840);
            _mARecord.eastings_cols      = ParseInt(buffer, 858);
            _mARecord.northings_rows     = ParseInt(buffer, 858); // WARNING. SHOULD NOT USE THIS VALUE. BUT WE ASSUME IS THE SAME WITH eastings SINCE IT IS ALWAYS THE CASE.
            _mARecord.suspect_void       = ParseInt(buffer, 886, 2);
            _mARecord.percent_void       = ParseInt(buffer, 896);

            // read the rest of the DEM
            StreamTokenizer tokenizer = new StreamTokenizer(reader, new char[] { ' ' });

            _mBRecord = null;
            for (int col = 0; col < _mARecord.eastings_cols; col++)
            {
                tokenizer.Next(); // row id
                tokenizer.Next(); // col id
                _mARecord.northings_rows = ToInt(tokenizer.Next());

                if (_mBRecord == null)
                {
                    _mBRecord = new BRecord(_mARecord.eastings_cols, _mARecord.northings_rows);
                }

                tokenizer.Next(); // skip next six fields
                tokenizer.Next();
                tokenizer.Next();
                tokenizer.Next();
                tokenizer.Next();
                tokenizer.Next();

                // for (int row = record.northings_rows - 1; row >= 0; row--)
                for (int row = 0; row < _mARecord.northings_rows; row++)
                {
                    _mBRecord.elevations[col, row] = ToShort(tokenizer.Next());
                }
            }

            reader.Close();
        }