zoukankan      html  css  js  c++  java
  • [Luogu] P1331 海战

    Luogu P1331 海战


    传送门

    这个题大概是找图形规律。首先,因为如果"Bad placement"的话,四个格里一定会有三个是'#'。其次,如果有船的话,这一块矩形的右下角一格的右边、下边一格一定都是空的,要不然就"Bad placement"了。

    #include <algorithm>
    #include <iostream>
    using namespace std;
    int r, c, tot;
    int map[1010][1010];
    char tmp;
    inline bool calc(int x, int y) {
        return ((map[x][y] + map[x + 1][y] + map[x][y + 1] + map[x + 1][y + 1]) == 3);
    }
    int main() {
        ios::sync_with_stdio(false);
        cin >> r >> c;
        for (int i = 1; i <= r; ++i)
            for (int j = 1; j <= c; ++j) {
                cin >> tmp;
                map[i][j] = tmp == '#' ? 1 : 0;
            }
        for (int i = 1; i <= r; ++i)
            for (int j = 1; j <= c; ++j) {
                if(calc(i, j)) {cout << "Bad placement.
    "; return 0;}
                if(map[i][j] && !map[i + 1][j] && !map[i][j + 1]) tot++;
            }
        cout << "There are " << tot << " ships.
    ";
        return 0;
    }
    
  • 相关阅读:
    驱动程序细节和权衡
    交互
    查找UI元素
    Selenium-Webdriver API命令和操作-Get & Wait
    Selenium的webdriver
    openssl生成ssl证书
    tony_nginx_02_URL重写
    CPA
    消息队列产品比较
    元数据交换绑定的秘密
  • 原文地址:https://www.cnblogs.com/manziqi/p/8529878.html
Copyright © 2011-2022 走看看