ICode9

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

#6030. 「雅礼集训 2017 Day1」矩阵

2020-03-02 18:06:28  阅读:226  来源: 互联网

标签:ch ++ void Tp Day1 雅礼 while 2017 define


无解肯定是一个都没有。
首先你要想到一个贪心策略
就是要染满一列,然后再染其他列
很显然可以用 \(k\) 行染 \(k\) 列,然后你发现,如果第 \(k\) 列没有?
随便挑个来染上,多1的代价。
最后的话,看一下有多少个没染完的,搞下就完了

只能scanf,wdnmd

// powered by c++11
// by Isaunoya
#include <bits/stdc++.h>
#define rep(i, x, y) for (register int i = (x); i <= (y); ++i)
#define Rep(i, x, y) for (register int i = (x); i >= (y); --i)
using namespace std;
using db = double;
using ll = long long;
using uint = unsigned int;
#define Tp template
using pii = pair<int, int>;
#define fir first
#define sec second
Tp<class T> void cmax(T& x, const T& y) {
    if (x < y)
        x = y;
}
Tp<class T> void cmin(T& x, const T& y) {
    if (x > y)
        x = y;
}
#define all(v) v.begin(), v.end()
#define sz(v) ((int)v.size())
#define pb emplace_back
Tp<class T> void sort(vector<T>& v) { sort(all(v)); }
Tp<class T> void reverse(vector<T>& v) { reverse(all(v)); }
Tp<class T> void unique(vector<T>& v) { sort(all(v)), v.erase(unique(all(v)), v.end()); }
const int SZ = 1 << 23 | 233;
struct FILEIN {
    char qwq[SZ], *S = qwq, *T = qwq, ch;
#ifdef __WIN64
#define GETC getchar
#else
    char GETC() { return (S == T) && (T = (S = qwq) + fread(qwq, 1, SZ, stdin), S == T) ? EOF : *S++; }
#endif
    FILEIN& operator>>(char& c) {
        while (isspace(c = GETC()))
            ;
        return *this;
    }
    FILEIN& operator>>(string& s) {
        while (isspace(ch = GETC()))
            ;
        s = ch;
        while (!isspace(ch = GETC())) s += ch;
        return *this;
    }
    Tp<class T> void read(T& x) {
        bool sign = 0;
        while ((ch = GETC()) < 48) sign ^= (ch == 45);
        x = (ch ^ 48);
        while ((ch = GETC()) > 47) x = (x << 1) + (x << 3) + (ch ^ 48);
        x = sign ? -x : x;
    }
    FILEIN& operator>>(int& x) { return read(x), *this; }
    FILEIN& operator>>(ll& x) { return read(x), *this; }
} in;
struct FILEOUT {
    const static int LIMIT = 1 << 22;
    char quq[SZ], ST[233];
    int sz, O;
    ~FILEOUT() { flush(); }
    void flush() {
        fwrite(quq, 1, O, stdout);
        fflush(stdout);
        O = 0;
    }
    FILEOUT& operator<<(char c) { return quq[O++] = c, *this; }
    FILEOUT& operator<<(string str) {
        if (O > LIMIT)
            flush();
        for (char c : str) quq[O++] = c;
        return *this;
    }
    Tp<class T> void write(T x) {
        if (O > LIMIT)
            flush();
        if (x < 0) {
            quq[O++] = 45;
            x = -x;
        }
        do {
            ST[++sz] = x % 10 ^ 48;
            x /= 10;
        } while (x);
        while (sz) quq[O++] = ST[sz--];
    }
    FILEOUT& operator<<(int x) { return write(x), *this; }
    FILEOUT& operator<<(ll x) { return write(x), *this; }
} out;
#define int long long

const int maxn = 1e3 + 31;
char a[maxn][maxn];
signed main() {
    // code begin.
    int n;
    scanf("%lld", &n);
    bool v = 0;
    vector<int> cntx(n + 3, 0), cnty(n + 3, 0);
    rep(i, 1, n) {
        scanf("%s", a[i] + 1);
        rep(j, 1, n) {
            if (a[i][j] == '#') {
                v = 1;
                ++cntx[i], ++cnty[j];
            }
        }
    }
    if (!v)
        out << -1 << '\n';
    else {
        int ans = n;
        rep(i, 1, n) if (cnty[i]) cmin(ans, n - cntx[i]);
        else cmin(ans, n - cntx[i] + 1);
        rep(i, 1, n) if (cnty[i] != n)++ ans;
        out << ans << '\n';
    }
    return 0;
    // code end.
}

标签:ch,++,void,Tp,Day1,雅礼,while,2017,define
来源: https://www.cnblogs.com/Isaunoya/p/12397059.html

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

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

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

ICode9版权所有