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

时间: 2024-08-11 16:22:56

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

Educational Codeforces Round 36 (Rated for Div. 2)

Educational Codeforces Round 36 (Rated for Div. 2) F. Imbalance Value of a Tree You are given a tree T consisting of n vertices. A number is written on each vertex; the number written on vertex i is ai. Let's denote the function I(x,?y) as the differ

Educational Codeforces Round 36 (Rated for Div. 2) 题解

Educational Codeforces Round 36 (Rated for Div. 2) 题目的质量很不错(不看题解做不出来,笑 Codeforces 920C 题意 给定一个\(1\)到\(n\)组成的数组,只可以交换某些相邻的位置,问是否可以将数组调整为升序的 解题思路 首先如果每个数都能通过交换到它应该到的位置,那么就可以调整为升序的. 但实际上交换是对称的,如果应该在的位置在当前位置前方的数都交换完成,那么整体就是排好序的,因为不可能所有不在相应位置的数都在相应位置的后方.

Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes

Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://codeforces.com/contest/985/problem/E Description Mishka received a gift of multicolored pencils for his birthday! Unfortunately he lives in a monochrome w

Educational Codeforces Round 55 (Rated for Div. 2)

Educational Codeforces Round 55 (Rated for Div. 2) 链接 A Vasya and Book 傻逼题..注意判边界. #include<cstdio> #include<cstring> #include<algorithm> #include<queue> #include<set> #include<map> #include<vector> #include<cm

Educational Codeforces Round 57 (Rated for Div. 2)

get人生第二场CF! 成绩:(exACM) rank858 AC3/7 Penalty57 rating1648(+52) 题目:Educational Codeforces Round 57 (Rated for Div. 2) 错题题解: D. Easy Problem E. The Top Scorer F. Inversion Expectation G. Lucky Tickets 原文地址:https://www.cnblogs.com/xht37/p/10198321.html

Educational Codeforces Round 58 (Rated for Div. 2)(待更新)

get人生第七场CF! 成绩:(exACM) rank AC3/7 Penalty104 rating() 题目:Educational Codeforces Round 58 (Rated for Div. 2) 错题题解: C. Division and Union 原文地址:https://www.cnblogs.com/xht37/p/10260260.html

Educational Codeforces Round 59 (Rated for Div. 2) DE题解

Educational Codeforces Round 59 (Rated for Div. 2) D. Compression 题目链接:https://codeforces.com/contest/1107/problem/D 题意: 给出一个n*(n/4)的矩阵,这个矩阵原本是一些01矩阵,但是现在四个四个储存进二进制里面,现在给出的矩阵为0~9以及A~F,表示0~15. 然后问这个矩阵能否压缩为一个(n/x)*(n/x)的矩阵,满足原矩阵中大小为x*x的子矩阵所有数都相等(所有子矩阵构

Codeforces Round #503 (by SIS, Div. 2)

Codeforces Round #503 (by SIS, Div. 2) https://codeforces.com/contest/1020 A 1 #include <iostream> 2 #include <cstring> 3 #include <cmath> 4 #include <algorithm> 5 #include <cstdio> 6 #include <cstdlib> 7 #include <s

Educational Codeforces Round 62 (Rated for Div. 2)

layout: post title: Educational Codeforces Round 62 (Rated for Div. 2) author: "luowentaoaa" catalog: true tags: mathjax: true - codeforces - dp --- " target="_blank" style="font-size:24px;">传送门 D - Minimum Triangulat