ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

CF ECR59div2 D

2019-03-02 19:44:21  阅读:213  来源: 互联网

标签:Matrix int rep ECR59div2 CF ec include define


题目本质:如果答案是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\n", 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 }

 

标签:Matrix,int,rep,ECR59div2,CF,ec,include,define
来源: https://www.cnblogs.com/AlphaWA/p/10462510.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有