zoukankan      html  css  js  c++  java
  • B. Filling the Grid codeforces

    题目链接:https://codeforces.com/contest/1228/problem/B

    #include <cstdio>
    #include <algorithm>
    #include <iostream>
    #include <vector>
    #include <cstring>
    #define mem(a,b) memset(a,b,sizeof(a))
    
    using namespace std;
    string a[1005];
    const int mod = 1e9+7;
    int dir[4][2] = {0,1,0,-1,1,0,-1,0};
     int main()
    {
        int h,w,r[1005],c[1005],ans[1005][1005];
        while(cin >> h >> w) {
            int flag = 0;
            memset(ans,0,sizeof(ans));
            for(int i = 1; i <= h;i++) {
                cin >> r[i];
            }
            for(int i = 1; i <= w; i++) {
                cin >> c[i];
            }
            //1 代表空 2 代表满
            for(int i = 1; i <= h; i++) {
                if(r[i] == 0) {
                    ans[i][1] = 1;
                    continue;
                }
                for(int j = 1; j <= r[i];j++) {
                    ans[i][j] = 2;
                }
                if(r[i] < w)//让最后一个满的下一个为空
                    ans[i][r[i]+1] = 1;
            }
            for(int i = 1; i <= w; i++) {
                if(c[i] == 0){
                    if(ans[1][i] == 2) {
                        flag = 1;
                        break;
                    }
                    ans[1][i] = 1;
                    continue;
                }
                for(int j = 1; j <= c[i]; j++) {
                    if(ans[j][i] == 1) {
                        flag = 1;
                        break;
                    }
                    ans[j][i] = 2;
                }
                if(flag == 1)
                    break;
                if(c[i] < h)
                {
                    if(ans[c[i]+1][i] == 2)
                    {
                        flag = 1;
                        break;
                    }
                    ans[c[i]+1][i] = 1;
                }
            }
            int sum = 0;
            for(int i = 1; i <= h; i++) {
                for(int j = 1; j <= w; j++) {
                    if(ans[i][j] == 0)
                        sum++;
                }
            }
            int anss = 0;
            for(int i = 0; i <= sum; i++)
                if(i == 0)
                    anss = 1;
                else {
                    anss*=2;
                    anss %= mod;
                }
            if(flag == 1) anss = 0; //如果不满足条件break掉的 答案为0
            cout << anss << endl;
        }
        return 0;
    }
  • 相关阅读:
    Create procedure
    json
    XSLT
    使用 ActiveMQ 示例
    使用Apache FtpServer搭建FTP服务器
    Publisher/Subscriber(发布/订阅者)消息模式开发流程
    使用 ActiveMQ 示例
    内嵌jetty
    基于Atom协议的数据接入规范
    C++创建jni 并且利用rundll32.exe调试jni程序
  • 原文地址:https://www.cnblogs.com/LLLAIH/p/11621722.html
Copyright © 2011-2022 走看看