思路:
输出 \(\lceil \frac{n}{x} \rceil\)
即可
时间复杂度:\(O(1)\)
1 2 3 4 5 6 7 8 9 10 11 signed main () { std::ios::sync_with_stdio (false ); std::cin.tie (nullptr ); int n, x; std::cin >> n >> x; std::cout << (n + x - 1 ) / x << "\n" ; return 0 ; }
思路:
时间复杂度:\(O(n^2)\)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 int n;struct Matrix { char g[15 ][15 ]; void init () { for (int i = 0 ; i < n; i++) { for (int j = 0 ; j < n; j++) { std::cin >> g[i][j]; } } } Matrix rotate () { Matrix ans; for (int i = 0 ; i < n; i++) { for (int j = 0 ; j < n; j++) { ans.g[i][j] = g[n - j - 1 ][i]; } } return ans; } Matrix reflex_x () { Matrix ans; for (int i = 0 ; i < n; i++) { for (int j = 0 ; j < n; j++) { ans.g[i][j] = g[n - i - 1 ][j]; } } return ans; } Matrix reflex_y () { Matrix ans; for (int i = 0 ; i < n; i++) { for (int j = 0 ; j < n; j++) { ans.g[i][j] = g[i][n - j - 1 ]; } } return ans; } bool operator == (Matrix b) { for (int i = 0 ; i < n; i++) { for (int j = 0 ; j < n; j++) { if (g[i][j] != b.g[i][j]) return false ; } } return true ; } }; signed main () { std::ios::sync_with_stdio (false ); std::cin.tie (nullptr ); std::cin >> n; Matrix a, b, c; a.init (), b.init (); for (int i = 0 ; i < 4 ; i++) { if (a == b) { std::cout << "Yes\n" ; return 0 ; } a = a.rotate (); } for (int i = 0 ; i < 4 ; i++) { c = a.reflex_x (); for (int j = 0 ; j < 4 ; j++) { if (c == b) { std::cout << "Yes\n" ; return 0 ; } c = c.rotate (); } a = a.reflex_x (); } for (int i = 0 ; i < 4 ; i++) { c = a.reflex_y (); for (int j = 0 ; j < 4 ; j++) { if (c == b) { std::cout << "Yes\n" ; return 0 ; } c = c.rotate (); } a = a.reflex_y (); } std::cout << "No\n" ; return 0 ; }
思路:
时间复杂度:\(O(a^2 \times
b^2)\)
附:勾股定理: \(a^2+b^2=c^2\) ,\(a\) , \(b\)
均为直角边,\(c\) 为斜边
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 signed main () { std::ios::sync_with_stdio (false ); std::cin.tie (nullptr ); int a, b; std::cin >> a >> b; for (int i = 1 ; i * i < a * a; i++) { for (int j = 1 ; j * j < b * b; j++) { int x1 = a * a - i * i, x2 = b * b - j * j; int y1 = sqrt (x1), y2 = sqrt (x2); if (y1 * y1 == x1 && y2 * y2 == x2) { if (y1 != y2 && i * j == y1 * y2) { std::cout << "YES\n" ; std::cout << "0 0\n" ; std::cout << -i << " " << y1 << "\n" ; std::cout << j << " " << y2 << "\n" ; return 0 ; } } } } std::cout << "NO\n" ; return 0 ; }