codeforces 432E Square Tiling

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-08-29 13:10:51

codeforces 432E Square Tiling的相关文章

Codeforces 432E Square Tiling(构造+贪心)

我们通常这么写 using (SqlDataReader drm = sqlComm.ExecuteReader()) { drm.Read();//以下把数据库中读出的Image流在图片框中显示出来. MemoryStream ms = new MemoryStream((byte[])drm["Logo"]); Image img = Image.FromStream(ms); this.pictureBox1.Image = img; } 我的写数据 private void b

codeforces 432E Square Tiling 贪心

题目大意:给定一个n?m的矩阵,要求用正方形砖块覆盖,使得任意两块同颜色的正方形砖块不相邻且字典序最小 枚举每一块砖,如果这个位置为空,就填入字典序最小的砖块,然后将边长一格格拓展 如果当前右侧位置可以填入字典序更小的砖块,就不拓展 否则判断能否拓展并拓展 #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define M 110 using name

Codeforces 895C Square Subsets(状压DP 或 异或线性基)

题目链接  Square Subsets 这是白书原题啊 先考虑状压DP的做法 2到70总共19个质数,所以考虑状态压缩. 因为数据范围是70,那么我们统计出2到70的每个数的个数然后从2考虑到70. 设dp[x][mask]为考虑到x这个数的时候,x这个数和之前的所有数中,选出某些数,他们的乘积分解质因数,所有的指数对2取模之后, 状态为mask的方案数. 然后就可以转移了……这个状压DP花了我好几个小时……真是弱啊 哦对最后还要特判1的情况. 每个1选或不选都可以,然后考虑只选1的情况,累加

Codeforces 895C - Square Subsets

题意: 给了n个数,要求有几个子集使子集中元素的和为一个数的平方. 题解: 因为每个数都可以分解为质数的乘积,所有的数都小于70,所以在小于70的数中一共只有19个质数.可以使用状压DP,每一位上0表示这个质数的个数为偶数个,1表示为奇数个.这样的话,如果某个数为一个数的平方的话,那么每个质数个数都是偶数,用0可以表示.从1-70开始状压DP,先存下每个数出现多少次,然后dp转移,dp转移时分别计算某个数出现奇数次还是偶数次的方案数. 这里有一个公式:C(n,0)+C(n,2)+--=C(n,1

Codeforces Round #246 (Div. 2)

A.Choosing Teams 水题 #include <cstdio> #include <cstring> using namespace std; int main() { int n, k, ans, i, x; scanf("%d%d",&n,&k); ans = 0; for(i=0; i<n; ++i) { scanf("%d",&x); if(5-x >= k) ans++; } ans

CodeForces 1A Theatre Square

A - Theatre Square Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 1A Description Theatre Square in the capital city of Berland has a rectangular shape with the size n × m meters. On the

Codeforces Round #249 (Div. 2) A. Black Square

水题 #include <iostream> #include <vector> #include <algorithm> using namespace std; int main(){ vector<int> a(4); cin >> a[0] >> a[1]>>a[2]>>a[3]; string str; cin >> str; int res = 0; for(int i = 0 ; i

Codeforces 828B Black Square(简单题)

Codeforces 828B Black Square(简单题) Description Polycarp has a checkered sheet of paper of size n?×?m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum pos

codeforces 711B - Chris and Magic Square

题目链接:http://codeforces.com/problemset/problem/711/B 题目大意: 输入 n ,输入 n*n 的矩阵,有一个占位 0 , 求得将 0 位置换成其他的整数 使得矩阵 行列斜 和全部相等. 代码状态: 一把辛酸泪