Lang:C#
Edit12345678910111213141516171819202122232425262728293031using 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;