Advertisement
SorahISA

D. ZZPooling 密碼池產生器 (zzpooling)

Oct 5th, 2022 (edited)
643
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.31 KB | Source Code | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5.     // ios_base::sync_with_stdio(0), cin.tie(0);
  6.    
  7.     string S; getline(cin, S);
  8.     int N; cin >> N;
  9.     char zigzag, pooling; cin >> zigzag >> pooling;
  10.     int poolsz; cin >> poolsz;
  11.    
  12.     if (zigzag == 'b') reverse(begin(S), end(S));
  13.    
  14.     vector<string> board(N);
  15.     for (int i = 0; i < N; ++i) board[i] = S.substr(i*N, N);
  16.    
  17.     auto valid = [&](int r, int c) -> bool {
  18.         return (0 <= r and r < N and 0 <= c and c < N);
  19.     };
  20.    
  21.     string zigstr;
  22.     for (int sum = 0; sum <= 2*N-2; ++sum) {
  23.         if (sum & 1) {for (int r = 0, c = sum; c >= 0; ++r, --c) if (valid(r, c)) zigstr += board[r][c];}
  24.         else         {for (int c = 0, r = sum; r >= 0; ++c, --r) if (valid(r, c)) zigstr += board[r][c];}
  25.     }
  26.    
  27.     for (int i = 0; i < N; i += poolsz) {
  28.         for (int j = 0; j < N; j += poolsz) {
  29.             int mx = 0, sum = 0;
  30.             for (int x = 0; x < poolsz; ++x) {
  31.                 for (int y = 0; y < poolsz; ++y) {
  32.                     mx = max(mx, (int)zigstr[(i+x)*N + (j+y)]);
  33.                     sum += zigstr[(i+x)*N + (j+y)];
  34.                 }
  35.             }
  36.             cout << (char)(pooling == 'a' ? sum / poolsz / poolsz : mx);
  37.         }
  38.     }
  39.     cout << "\n";
  40.    
  41.     return 0;
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement