Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Exams_Prep
- {
- class Program
- {
- static void FireDown(int[,] forest, int positionX, int positionY)
- {
- if (positionX < 0 || positionY < 0 || positionX >= forest.GetLength(0) || positionY >= forest.GetLength(1))
- {
- return;
- }
- if (forest[positionX, positionY] == 0)
- {
- return;
- }
- if (forest[positionX, positionY] == 1)
- {
- forest[positionX, positionY] = 0;
- for (int x = -1; x <= 1; x++)
- {
- for (int y = -1; y <= 1; y++)
- {
- if (x == 0 && y == 0)
- {
- continue;
- }
- FireDown(forest, positionX + x, positionY + y);
- }
- }
- }
- }
- static void PrintForest(int[,] forest)
- {
- for (int i = 0; i < forest.GetLength(0); i++)
- {
- for (int j = 0; j < forest.GetLength(1); j++)
- {
- Console.Write($"{forest[i, j]} ");
- }
- Console.WriteLine();
- }
- }
- static void Main(string[] args)
- {
- int m = 5;
- int n = 6;
- int[,] forest = new int[,] {
- { 0, 1, 0, 0, 0, 1 },
- { 0, 1, 0, 0, 1, 1 },
- { 0, 0, 1, 1, 0, 0 },
- { 0, 0, 0, 1, 0, 0 },
- { 0, 0, 0, 0, 0, 1 }
- };
- int fires = 0;
- for (int i = 0; i < forest.GetLength(0); i++)
- {
- for (int j = 0; j < forest.GetLength(1); j++)
- {
- if (forest[i, j] == 1)
- {
- fires++;
- FireDown(forest, i, j);
- }
- }
- }
- Console.WriteLine("Fires " + fires);
- }
- static void GeneratePermutations(int n)
- {
- int[] permutation = new int[n];
- GeneratePermutationsHelper(permutation, 0);
- }
- static void GeneratePermutationsHelper(int[] permutation, int index)
- {
- if (index == permutation.Length)
- {
- // Print the permutation
- Console.WriteLine(string.Join(" ", permutation));
- }
- else
- {
- // Generate permutations with 0 and 1
- for (int i = 0; i <= 1; i++)
- {
- permutation[index] = i;
- GeneratePermutationsHelper(permutation, index + 1);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement