码迷,mamicode.com
首页 > 其他好文 > 详细

Mosaic

时间:2019-04-06 11:10:52      阅读:117      评论:0      收藏:0      [点我收藏+]

标签:span   clu   const   typedef   type   ios   def   space   style   

给你三个数字a,b,c,让你用1~m的数字凑出来

结论:有2个1和2个2肯定凑不出来,然后就搜索

#include <bits/stdc++.h>
using namespace std;
#define rep(i, j, k) for (int i = int(j); i <= int(k); ++ i) 
#define dwn(i, j, k) for (int i = int(j); i >= int(k); -- i)
typedef long long LL;
typedef pair<int, int> P;
const int N = 3e5 + 7;
char col[N];
int dfs(int i, int j, int k, int x) {
    if (i == 0 && j == 0 && k == 0) return 1;
    if (i < 0 || j < 0 || k < 0 || x <= 0) return 0;
    col[x] = 1;
    if (dfs(i - x, j, k, x - 1)) return 1;
    col[x] = 2;
    if (dfs(i, j - x, k, x - 1)) return 1;
    col[x] = 3;
    if (dfs(i, j, k - x, x - 1)) return 1;
    return 0;
}
int main() {
    ios::sync_with_stdio(0);
    LL a, b, c;
    cin >> a >> b >> c;
    LL n = a + b + c;
    LL x = 1;
    for (x = 1; n > 0; x ++) n -= x; x --; int xx = x;
    int c1 = (a == 1) + (b == 1) + (c == 1);
    int c2 = (a == 2) + (b == 2) + (c == 2);
    if (c1 >= 2 || c2 >= 2 || n != 0) {
        printf("Impossible\n");
        return 0;
    }
    dfs(a, b, c, x);
    // cout << a << ‘ ‘ << b << ‘ ‘ << c << ‘ ‘ << x << ‘\n‘;
    auto tran = [&](int x) -> char {
        if (x == 1) return W;
        if (x == 2) return G;
        return B;
    };
    rep(i, 1, xx) printf("%c", tran(col[i]));
}
/*
11 5 5
*/

 

Mosaic

标签:span   clu   const   typedef   type   ios   def   space   style   

原文地址:https://www.cnblogs.com/tempestT/p/10661076.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!