codeforces 432E Square Tiling
题意
题解
代码
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define sz(x) (int)x.size()
#define de(x) cout<< #x<<" = "<<x<<endl
#define dd(x) cout<< #x<<" = "<<x<<" "
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int N = 111;
int n, m;
bool in[N][N];
int ans[N][N], ban[N][N];
int calc(int x) {
for(int i = 0; ; ++i) if(!(x>>i&1)) return i;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
cin >> n >> m;
rep(i, 1, n+1) rep(j, 1, m+1) in[i][j] = 1;
memset(ans, -1, sizeof(ans));
rep(i, 1, n+1) rep(j, 1, m+1) if(ans[i][j]==-1) {
int c = calc(ban[i][j]), k;
rep(t, 1, n+1) {
bool ok = 1;
if(i+t-1>n||j+t-1>m) ok = 0;
rep(x, i, i+t) if(ans[x][j+t-1]!=-1 || calc(ban[x][j+t-1])>c) ok = 0;
rep(y, j, j+t) if(ans[y][i+t-1]!=-1 || calc(ban[y][i+t-1])>c) ok = 0;
if(!ok) break;
k = t;
if(j+t<=m&&c>calc(ban[i][j+t])) break;
}
rep(x, i, i+k) rep(y, j, j+k) ans[x][y] = c;
rep(x, i, i+k) ban[x][j-1] |= (1<<c), ban[x][j+k] |= (1<<c);
rep(y, j, j+k) ban[i-1][y] |= (1<<c), ban[i+k][y] |= (1<<c);
}
rep(i, 1, n+1) {
rep(j, 1, m+1) cout << (char)(ans[i][j]+‘A‘);
cout << endl;
}
return 0;
}
原文地址:https://www.cnblogs.com/wuyuanyuan/p/9297175.html
时间: 2024-11-07 04:33:52