Advertisement
Dmaxiya

钉板上的正方形 参考代码

Apr 7th, 2025
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.81 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long LL;
  5. const int maxn = 200000 + 100;
  6. struct Vector {
  7.     int x, y;
  8.     Vector() : x(0), y(0) {}
  9.     Vector(int x, int y) : x(x), y(y) {}
  10. };
  11.  
  12. Vector operator+(const Vector &a, const Vector &b) {
  13.     return Vector(a.x + b.x, a.y + b.y);
  14. }
  15.  
  16. int operator*(const Vector &a, const Vector &b) {
  17.     return a.x * b.x + a.y * b.y;
  18. }
  19.  
  20. Vector rotate90(const Vector &v) {
  21.     return Vector(Vector(0, -1) * v, Vector(1, 0) * v);
  22. }
  23.  
  24. int n = 10;
  25. set<int> st;
  26. string G[10] = {
  27.     "1101011111",
  28.     "1110011110",
  29.     "1100101111",
  30.     "1011011110",
  31.     "1010111100",
  32.     "1001010101",
  33.     "1111111110",
  34.     "0111111110",
  35.     "0110101111",
  36.     "1010010100"
  37. };
  38.  
  39. bool judge(const Vector &p) {
  40.     return p.x >= 0 && p.x < n && p.y >= 0 && p.y < n && G[p.x][p.y] == '1';
  41. }
  42.  
  43. bool judge(int x1, int y1, int x2, int y2) {
  44.     Vector v(x2 - x1, y2 - y1);
  45.     v = rotate90(v);
  46.     Vector p = Vector(x2, y2) + v;
  47.     if (!judge(p)) {
  48.         return false;
  49.     }
  50.     v = rotate90(v);
  51.     p = p + v;
  52.     return judge(p);
  53. }
  54.  
  55. int main() {
  56. #ifdef ExRoc
  57.     freopen("test.txt", "r", stdin);
  58. #endif // ExRoc
  59.     ios::sync_with_stdio(false);
  60.  
  61.     for (int i = 0; i < n; ++i) {
  62.         for (int j = 0; j < n; ++j) {
  63.             if (G[i][j] != '1') {
  64.                 continue;
  65.             }
  66.             for (int k = 0; k < n; ++k) {
  67.                 for (int l = 0; l < n; ++l) {
  68.                     if (G[k][l] != '1') {
  69.                         continue;
  70.                     }
  71.                     if (judge(i, j, k, l)) {
  72.                         Vector v(k - i, l - j);
  73.                         st.insert(v * v);
  74.                     }
  75.                 }
  76.             }
  77.         }
  78.     }
  79.     st.erase(0);
  80.     cout << st.size() << endl;
  81.  
  82.     return 0;
  83. }
  84.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement