Created
May 1, 2015 02:13
-
-
Save petiahr/02ace58090e5d12384ed to your computer and use it in GitHub Desktop.
Bits at CrossRoad
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
class Program | |
{ | |
static void Main() | |
{ | |
int n = int.Parse(Console.ReadLine()); | |
uint[,] array = new uint[n, n]; | |
uint[,] sum = new uint[n, n]; | |
string[,] crossed = new string[n, n]; | |
int count = 0; | |
while (true) | |
{ | |
string str = Console.ReadLine(); | |
string[] input = str.Split(); | |
if (str == "end") | |
{ | |
break; | |
} | |
for (int i = 0; i < n; i++) | |
{ | |
for (int j = 0; j < n; j++) | |
{ | |
array[i, j] = 0; | |
} | |
} | |
int first = int.Parse(input[0].ToString()); | |
int second = int.Parse(input[1].ToString()); | |
array[first, n - 1 - second] = 1; | |
crossed[first, n - 1 - second] = "T"; | |
bool isFixed = true; | |
for (int i = 0; i < n; i++) | |
{ | |
{ | |
for (int j = 0; j < n; j++) | |
{ | |
if (array[i, j] == 1 & isFixed == true) | |
{ | |
int l = 1; | |
int k = 1; | |
while ((i - l >= 0) & (j - k >= 0)) | |
{ | |
array[i - l, j - k] = 1; | |
l++; | |
k++; | |
isFixed = false; | |
} | |
int s = 1; | |
int p = 1; | |
while ((i - s >= 0) & (j + p <= n - 1)) | |
{ | |
array[i - s, j + p] = 1; | |
s++; | |
p++; | |
isFixed = false; | |
} | |
int t = 1; | |
int f = 1; | |
while ((i + t <= n - 1) & (j + f <= n - 1)) | |
{ | |
array[i + t, j + f] = 1; | |
t++; | |
f++; | |
isFixed = false; | |
} | |
int q = 1; | |
int r = 1; | |
while ((i + q <= n - 1) & (j - r >= 0)) | |
{ | |
array[i + q, j - r] = 1; | |
q++; | |
r++; | |
isFixed = false; | |
} | |
} | |
} | |
} | |
} | |
for (int i = 0; i < n; i++) | |
{ | |
for (int j = 0; j < n; j++) | |
{ | |
if (sum[i, j] == 1 & array[i, j] == 1) | |
{ | |
sum[i, j] = 1; | |
crossed[i, j] = "T"; | |
} | |
else if (sum[i, j] == 0 & array[i, j] == 0) | |
{ | |
sum[i, j] = 0; | |
} | |
else | |
{ | |
sum[i, j] = 1; | |
} | |
} | |
} | |
}// end of while | |
long number = 0; | |
for (int i = 0; i < n; i++) | |
{ | |
for (int j = 0; j < n; j++) | |
{ | |
number = number + (long)Math.Pow(2, n - 1 - j) * sum[i, j]; | |
if (crossed[i, j] == "T") | |
{ | |
count++; | |
} | |
} | |
Console.WriteLine(number); | |
number = 0; | |
} | |
Console.WriteLine(count); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment