hihoCoder太阁最新面经算法竞赛10 register

Ended

Participants:138

Verdict:Accepted
Score:100 / 100
Submitted:2016-07-24 22:03:35

Lang:C#

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
    class Program
    {
        static int[,] b = new int[u, u]; const int u = 1001; static int tag, cur;
        static void Mov(int x, int y)
        {
            int p = 0, q = 0;
            Action act = () => { if (p > -1 && p < u && q > -1 && q < u && b[p, q] == cur) { b[p, q] = tag; Mov(p, q); } };
            p = x - 1; q = y; act();
            p = x + 1; q = y; act();
            p = x; q = y - 1; act();
            p = x; q = y + 1; act();
        }
        static void Main(string[] args)
        {
            //Console.SetIn(new StreamReader(@"C:\Users\sedem_000\Desktop\hi.txt"));
            string[] s = Console.In.ReadToEnd().Split(new char[] { '\r', '\n', ' ' }, StringSplitOptions.RemoveEmptyEntries); int f = 0;
            int n = int.Parse(s[f++]) + 1; int[] d = new int[n];
            int R = 0; for (int i = 1; i < n; ++i)
            {
                int x = int.Parse(s[f++]), y = int.Parse(s[f++]); if (b[x, y] > 0) { Console.WriteLine(R); continue; }
                ++R;
                b[x, y] = i; d[i] = 1;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX