Advertisement
vencinachev

Exam

Oct 14th, 2023
792
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.86 KB | None | 0 0
  1. using System;
  2.  
  3.  
  4. namespace Exams_Prep
  5. {
  6.     class Program
  7.     {
  8.  
  9.         static void FireDown(int[,] forest, int positionX, int positionY)
  10.         {
  11.             if (positionX < 0 || positionY < 0 || positionX >= forest.GetLength(0) || positionY >= forest.GetLength(1))
  12.             {
  13.                 return;
  14.             }
  15.             if (forest[positionX, positionY] == 0)
  16.             {
  17.                 return;
  18.             }
  19.             if (forest[positionX, positionY] == 1)
  20.             {
  21.                 forest[positionX, positionY] = 0;
  22.                 for (int x = -1; x <= 1; x++)
  23.                 {
  24.                     for (int y = -1; y <= 1; y++)
  25.                     {
  26.                         if (x == 0 && y == 0)
  27.                         {
  28.                             continue;
  29.                         }
  30.                         FireDown(forest, positionX + x, positionY + y);
  31.                     }
  32.                 }
  33.             }
  34.         }
  35.  
  36.         static void PrintForest(int[,] forest)
  37.         {
  38.             for (int i = 0; i < forest.GetLength(0); i++)
  39.             {
  40.                 for (int j = 0; j < forest.GetLength(1); j++)
  41.                 {
  42.                     Console.Write($"{forest[i, j]} ");
  43.                 }
  44.                 Console.WriteLine();
  45.             }
  46.         }
  47.         static void Main(string[] args)
  48.         {
  49.             int m = 5;
  50.             int n = 6;
  51.             int[,] forest = new int[,] {
  52.                { 0, 1, 0, 0, 0, 1 },
  53.                { 0, 1, 0, 0, 1, 1 },
  54.                { 0, 0, 1, 1, 0, 0 },
  55.                { 0, 0, 0, 1, 0, 0 },
  56.                { 0, 0, 0, 0, 0, 1 }
  57.             };
  58.             int fires = 0;
  59.             for (int i = 0; i < forest.GetLength(0); i++)
  60.             {
  61.                 for (int j = 0; j < forest.GetLength(1); j++)
  62.                 {
  63.                     if (forest[i, j] == 1)
  64.                     {
  65.                         fires++;
  66.                         FireDown(forest, i, j);
  67.                     }
  68.                 }
  69.             }
  70.             Console.WriteLine("Fires " + fires);
  71.            
  72.         }
  73.  
  74.         static void GeneratePermutations(int n)
  75.         {
  76.             int[] permutation = new int[n];
  77.             GeneratePermutationsHelper(permutation, 0);
  78.         }
  79.  
  80.         static void GeneratePermutationsHelper(int[] permutation, int index)
  81.         {
  82.             if (index == permutation.Length)
  83.             {
  84.                 // Print the permutation
  85.                 Console.WriteLine(string.Join(" ", permutation));
  86.             }
  87.             else
  88.             {
  89.                 // Generate permutations with 0 and 1
  90.                 for (int i = 0; i <= 1; i++)
  91.                 {
  92.                     permutation[index] = i;
  93.                     GeneratePermutationsHelper(permutation, index + 1);
  94.                 }
  95.             }
  96.         }
  97.     }
  98. }
  99.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement