Advertisement
VNM24ix

25 Points

Jun 12th, 2025
679
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.47 KB | Source Code | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace _25points;
  6.  
  7. public static class Program {
  8.   public static void Main() {
  9.     int size = 9, size2 = size * size;
  10.     int X(int n) => n / size;
  11.     int Y(int n) => n % size;
  12.     int cnt;
  13.     int max = size * 2;
  14.     var p = new int[max];
  15.     void Show() {
  16.       for (int i = 0; i < cnt; i++)
  17.         Console.Write($" ({X(p[i])};{Y(p[i])})");
  18.     }
  19.     void Show1() {
  20.       Console.WriteLine();
  21.       for (int i = 0; i < size2; i++) {
  22.  
  23.         if (Array.IndexOf(p, i) >= 0) {
  24.           Console.ForegroundColor = ConsoleColor.Red;
  25.           Console.Write(" •");
  26.         } else {
  27.           Console.ForegroundColor = ConsoleColor.Yellow;
  28.           Console.Write(" •");
  29.         }
  30.         if ((i + 1) % size == 0) Console.Write("\n");
  31.       }
  32.       Console.ForegroundColor = ConsoleColor.White;
  33.     }
  34.     bool Test() {
  35.       if (cnt < 3) return true;
  36.       double x = X(p[cnt - 1]), y = Y(p[cnt - 1]);
  37.       for (int i = 0; i < cnt - 2; i++) {
  38.         double x1 = X(p[i]), y1 = Y(p[i]);
  39.         for (int j = i + 1; j < cnt - 1; j++) {
  40.           double x2 = X(p[j]), y2 = Y(p[j]);
  41.           if ((x - x1) * (y - y2) == (x - x2) * (y - y1)) return false;
  42.         }
  43.       }
  44.       return true;
  45.     }
  46.     bool[,] F() {
  47.       var f = new bool[size, size];
  48.       for (int i = 0; i < max; i++) {
  49.         f[X(p[i]), Y(p[i])] = true;
  50.       }
  51.       return f;
  52.     }
  53.     bool Eq(bool[,] f0, bool[,] f) {
  54.       bool[,] Copy(bool[,] f) {
  55.         var ff = new bool[size, size];
  56.         for (int i = 0; i < size; i++)
  57.           for (int j = 0; j < size; j++)
  58.             ff[i, j] = f[i, j];
  59.         return ff;
  60.       }
  61.       bool[,] Op1(bool[,] f) {
  62.         var ff = new bool[size, size];
  63.         for (int i = 0; i < size; i++)
  64.           for (int j = 0; j < size; j++)
  65.             ff[size - 1 - i, j] = f[i, j];
  66.         return ff;
  67.       }
  68.       bool[,] Op2(bool[,] f) {
  69.         var ff = new bool[size, size];
  70.         for (int i = 0; i < size; i++)
  71.           for (int j = 0; j < size; j++)
  72.             ff[j, i] = f[i, j];
  73.         return ff;
  74.       }
  75.       var ff = Copy(f0);
  76.       for (int i = 0; i < 8; i++) {
  77.         bool eq = true;
  78.         ff = ((i & 1) == 0 ? Op1(ff) : Op2(ff));
  79.         for (int j = 0; j < size; j++)
  80.           for (int k = 0; k < size; k++)
  81.             if (ff[j, k] != f[j, k]) eq = false;
  82.         if (eq) return true;
  83.       }
  84.       return false;
  85.     }
  86.     var l = new List<bool[,]>();
  87.     cnt = 1;
  88.     int cnt1 = 0;
  89.     p[0] = 0;
  90.     bool tst = true;
  91.     while (cnt > 0) {
  92.       if (tst) {
  93.         //Console.Clear();
  94.         //Show();
  95.         if (cnt == max) {
  96.           //Console.Clear();
  97.           //Console.WriteLine("OK" + (++cnt1));
  98.           bool[,] f = F();
  99.           bool test1 = true;
  100.           for (int i = 0; i < l.Count; i++)
  101.             if (Eq(l[i], f)) { test1 = false; break; }
  102.           if (test1) {
  103.             Show1();
  104.             l.Add(f);
  105.           }
  106.           //return;
  107.           //Console.ReadLine();
  108.           tst = false;
  109.         } else {
  110.           if (p[cnt - 1] < size2 - 1) {
  111.             cnt++;
  112.             p[cnt - 1] = p[cnt - 2] + 1;
  113.             tst = Test();
  114.           } else {
  115.             cnt--;
  116.             tst = false;
  117.           }
  118.         }
  119.       } else {
  120.         if (p[cnt - 1] < size2 - 1) {
  121.           p[cnt - 1]++;
  122.           tst = Test();
  123.         } else cnt--;
  124.       }
  125.  
  126.     }
  127.     Console.WriteLine(l.Count);
  128.   }
  129. }
  130.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement