zoukankan      html  css  js  c++  java
  • Codeforces Round #363 (Div. 2) One Bomb

    One Bomb

    题意:

    只有一个炸弹,并且一个只能炸一行和一列的‘*’,问最后能否炸完所以‘*’,如果可以输出炸弹坐标

    题解:

    这题做的时候真的没什么好想法,明知道b题应该不难,但只会瞎写,最后越写越乱,我就放弃了。看了题解,果然还是我不行。。。
    首先枚举一遍,记录总‘*'数,和每行,每列的‘*’数,之后再枚举一遍,看是否一行一列的‘*’数和总‘*'数相等,如果是,那就是答案,如果没有,就是NO。

    代码:

    #include <bits/stdc++.h>
    using namespace std;
    
    typedef long long ll;
    const int INF=0x3f3f3f3f;
    const ll LINF=0x3f3f3f3f3f3f3f3f;
    #define PI(A) cout<<A<<endl
    #define SI(N) cin>>N
    #define SII(N,M) cin>>N>>M
    #define cle(a,val) memset(a,(val),sizeof(a))
    #define rep(i,b) for(int i=0;i<(b);i++)
    #define Rep(i,a,b) for(int i=(a);i<=(b);i++)
    #define reRep(i,a,b) for(int i=(a);i>=(b);i--)
    #define dbg(x) cout <<#x<<" = "<<x<<endl
    #define PIar(a,n) rep(i,n)cout<<a[i]<<" ";cout<<endl;
    #define PIarr(a,n,m) rep(aa,n){rep(bb, m)cout<<a[aa][bb]<<" ";cout<<endl;}
    const double EPS= 1e-9 ;
    
    /*  /////////////////////////     C o d i n g  S p a c e     /////////////////////////  */
    
    const int MAXN= 1000 + 9 ;
    
    string s[MAXN];
    int a[MAXN],b[MAXN];
    int N,M;
    
    int main()
    {
        iostream::sync_with_stdio(false);
        cin.tie(0),cout.tie(0);
        while(SII(N,M))
        {
            cle(a,0);
            cle(b,0);
            rep(i,N) SI(s[i]);
            ll wall=0;
            rep(i,N)
            {
                rep(j,M)
                if (s[i][j]=='*')
                {
                    wall++;
                    a[i]++;
                    b[j]++;
                }
            }
            bool fl=0;
            int ax=0,ay=0;
            rep(i,N)
            {
                rep(j,M)
                {
                    ll ans=a[i]+b[j]-(s[i][j]=='*'?1:0);
                    if (ans==wall)
                    {
                        fl=1;
                        ax=i,ay=j;
                    }
                }
            }
            if(fl)
            {
                puts("YES");
                printf("%d %d
    ",ax+1,ay+1);
            }
            else puts("NO");
        }
        return 0;
    }
  • 相关阅读:
    MFC绘制直角坐标系
    mfc画波形函数
    ciscn_2019_ne_5
    ciscn_2019_n_5
    [ZJCTF 2019]NiZhuanSiWei
    ciscn_2019_n_1
    pwn-100
    2014提高组笔试错题
    BZOJ3211: 花神游历各国
    主席树模板
  • 原文地址:https://www.cnblogs.com/s1124yy/p/5726889.html
Copyright © 2011-2022 走看看