zoukankan      html  css  js  c++  java
  • CF ECR59div2 D

    题目本质:如果答案是i,那么从行和列两维都会满足:以i的倍数分块,矩阵值相同。

    一种解决方法:

    1.首先题目里说了要在n的约数里找orzorz……

    2.块中需要一整排都相同。用“与前一排相同否?”来判定,而每块的第一排允许与上一排不同。复杂度还是n^2。

    1 rep(i, 2, n) {
    2         ec[i] = true;
    3         rep(j, 1, n) {
    4             if (Matrix[i][j] != Matrix[i - 1][j]) {
    5                 ec[i] = false;
    6                 break;
    7             }
    8         }
    9     }

    行和列都弄一遍以上代码。

      1 #pragma comment(linker, "/STACK:1024000000,1024000000")
      2 #include <cstdio>
      3 #include <cstring>
      4 #include <cstdlib>
      5 #include <cmath>
      6 #include <ctime>
      7 #include <cctype>
      8 #include <climits>
      9 #include <iostream>
     10 #include <iomanip>
     11 #include <algorithm>
     12 #include <string>
     13 #include <sstream>
     14 #include <stack>
     15 #include <queue>
     16 #include <set>
     17 #include <map>
     18 #include <vector>
     19 #include <list>
     20 #include <fstream>
     21 #define ri readint()
     22 #define gc getchar()
     23 #define R(x) scanf("%d", &x)
     24 #define W(x) printf("%d
    ", x)
     25 #define init(a, b) memset(a, b, sizeof(a))
     26 #define rep(i, a, b) for (int i = a; i <= b; i++)
     27 #define irep(i, a, b) for (int i = a; i >= b; i--)
     28 #define ls p << 1
     29 #define rs p << 1 | 1
     30 using namespace std;
     31 
     32 typedef double db;
     33 typedef long long ll;
     34 typedef unsigned long long ull;
     35 typedef pair<int, int> P;
     36 const int inf = 0x3f3f3f3f;
     37 const ll INF = 1e18;
     38 
     39 inline int readint() {
     40     int x = 0, s = 1, c = gc;
     41     while (c <= 32)    c = gc;
     42     if (c == '-')    s = -1, c = gc;
     43     for (; isdigit(c); c = gc)
     44         x = x * 10 + c - 48;
     45     return x * s;
     46 }
     47 
     48 const int maxn = 5205;
     49 int n;
     50 string s;
     51 int Matrix[maxn][maxn];
     52 bool ec[maxn], er[maxn];
     53 
     54 void Deal(int i, string s) {
     55     rep(ss, 0, s.length() - 1) {
     56         int k = isdigit(s[ss]) ? s[ss] - '0' : 10 + s[ss] - 'A';
     57         rep(t, 0, 3) {
     58             Matrix[i][(ss << 2) + t + 1] = k >> (3 - t) & 1;
     59         }
     60     }
     61 }
     62 
     63 int solve() {
     64     rep(i, 2, n) {
     65         ec[i] = true;
     66         rep(j, 1, n) {
     67             if (Matrix[i][j] != Matrix[i - 1][j]) {
     68                 ec[i] = false;
     69                 break;
     70             }
     71         }
     72     }
     73     rep(j, 2, n) {
     74         er[j] = true;
     75         rep(i, 1, n) {
     76             if (Matrix[i][j] != Matrix[i][j - 1]) {
     77                 er[j] = false;
     78                 break;
     79             }    
     80         }
     81     }
     82 
     83     irep(i, n, 1) {
     84         if (n % i)    continue;
     85         bool flag = true;
     86         rep(j, 1, n) {
     87             if ((j - 1) % i != 0 && (not ec[j] || not er[j])) {
     88                 flag = false;
     89                 break;
     90             }
     91         }
     92         if (flag)    return i;
     93     }
     94 }
     95 
     96 int main() {
     97     ios_base::sync_with_stdio(false);
     98     cin.tie(0);
     99 
    100     cin >> n;
    101     rep(i, 1, n) {
    102         cin >> s;
    103         Deal(i, s);
    104     }
    105 
    106     cout << solve() << endl;
    107     return 0;
    108 }
  • 相关阅读:
    静态库,动态库
    vim
    消息队列-Rabbitmq处理消息及在Spring中的应用
    消息队列 -- 队列(Queue)和主题(Topic)
    Sing的签名算法
    Jquery
    VUE
    node
    vue 加载静态图片
    vue :style 动态绑定style
  • 原文地址:https://www.cnblogs.com/AlphaWA/p/10462510.html
Copyright © 2011-2022 走看看