Skip to content

Instantly share code, notes, and snippets.

@unilecs
Created July 11, 2019 05:49
Show Gist options
  • Save unilecs/62f77200f629196ddd0e574cb5d9bc32 to your computer and use it in GitHub Desktop.
Save unilecs/62f77200f629196ddd0e574cb5d9bc32 to your computer and use it in GitHub Desktop.
Задача: Детский утренник
using System;
public class Program
{
private static int GetSamePositionsByPermutation(int n, int m)
{
int[,] arr1 = new int[n, m];
int[,] arr2 = new int[n, m];
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
arr1[i, j] = i * m + j + 1;
arr2[i, j] = j * n + i + 1;
}
}
int count = 0;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
if (arr1[i, j] == arr2[i, j])
{
count++;
}
}
}
return count;
}
public static void Main()
{
Console.WriteLine("UniLecs");
Console.WriteLine(string.Format("Answer = {0}", GetSamePositionsByPermutation(3, 3))); // 2
Console.WriteLine(string.Format("Answer = {0}", GetSamePositionsByPermutation(3, 4))); // 3
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment