Codeforces Round #583 (Div. 1 + Div. 2, based on Olympiad of Metropolises), problem: (D) Treasure Island

题目大意
给你一个n*m 的棋盘 有的地方不能过 问题最少需要堵多少次 才能让(1,1)到(n,m)没有路径通过


解法:
打表发现 对角线最后剩下的通路最少 即为答案
画图可知$ 2*2$的子矩形内 右对角线被填满时左对角线都不能到达
递推判断即可
细节蛮多的


code:

#include<stdio.h>
#include<iostream>
#include<cstring>
#include<cmath>
#include<stdio.h>
#include<algorithm>
#include<vector>
#define maxnn 1000100
#define ll long long
using namespace std;
vector<int > Q[maxnn];
int n,m;
int main()
{
    char c;
    cin>>n>>m;
    for(int i=0;i<=m+1;i++) Q[0].push_back(3);
    for(int j=1;j<=n;j++) Q[j].push_back(3);
    int j=n+1;
    for(int i=0;i<=m+1;i++)Q[j].push_back(3);
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            c=getchar();
            while(c!='#'&&c!='.') c=getchar();
            if(c=='#') Q[i].push_back(3);
            else Q[i].push_back(1);
        }
    }
    for(int i=1;i<=n;i++) Q[i].push_back(3);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
        {
            if((i!=1||j!=1)&&(i!=n||j!=m))
               {
                   if(Q[i][j-1]==3&&Q[i-1][j]==3)
                       Q[i][j]=3;
               }
        }
    
    for(int i=n;i>=1;i--)
        for(int j=m;j>=1;j--)
        {
            if((i!=1||j!=1)&&(i!=n||j!=m))
            {
                if(Q[i][j+1]==3&&Q[i+1][j]==3)
                    Q[i][j]=3;
            }
        }
    int ans=100000;
    for(int j=1;j<=n+m;j++)
    {
        if(j!=1)
        {
            int tmp=j;
            int i=1;
            int tt=0;
            int ty=0;
            while(tmp>m) {tmp--;i++;}
            int fla=0;
            while(tmp>0&&i<=n&&(tmp!=m||i!=n))
            {
                
                fla=1;
                    tt++;
                    if(Q[i][tmp]==3)
                    {
                        ty++;
                    }
                tmp--;
                i++;
            }
            if(fla)
            ans=min(ans,tt-ty);
        }
    }
    cout<<ans<<endl;
}
刀剑映出了战士的心。而我的心,漆黑且残破
原文地址:https://www.cnblogs.com/OIEREDSION/p/11483783.html