城堡

news/2024/6/18 23:44:32

题目:

  给出一张地图,每个位置的值意义如下:

    一个数字有以下四个数中的若干个构成:

              1:西面有墙。

              2:北面有墙。

              4:东面有墙。

              8:南面有墙。

  这个题我因为一个小错误考试只得了10分,后来又调了很久。。。

  终于,聪明的我发现我没有按题目要求做,把优先级搞错了(西面房间的优先级应该最高)

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<math.h>
using namespace std;
int m,n,t,c;
int f[5000][6],color[5000],s[5000];
void dfs(int  x,int     y)
{
    color[x]=y;
    for(int i=1;i<=f[x][0];i++)
    {
        t=f[x][i];
        if(!color[t])
            dfs(t,y);
    }
    return ;
}
int main()
{
    freopen("fortress.in","r",stdin);
    freopen("fortress.out","w",stdout);
    scanf("%d%d",&m,&n);    
    for(int i=1;i<=n;i++)
    for(int j=1;j<=m;j++)
    {
        scanf("%d",&c);
        if(c<8&&i!=n)    f[i*m+j][++f[i*m+j][0]]=i*m+j+m;else c-=8;
        if(c<4&&j!=m)    f[i*m+j][++f[i*m+j][0]]=i*m+j+1;else c-=4;
        if(c<2&&i!=1)    f[i*m+j][++f[i*m+j][0]]=i*m+j-m;else c-=2;
        if(c<1&&j!=1)    f[i*m+j][++f[i*m+j][0]]=i*m+j-1;
    }
    int sum=0,maxn1=0;
    for(int i=1;i<=n;i++)
    for(int j=1;j<=m;j++)    
        if(!color[i*m+j])
            dfs(i*m+j,i*m+j),sum++;
    for(int i=1;i<=n;i++)
    for(int j=1;j<=m;j++)
        ++s[color[i*m+j]],maxn1=max(maxn1,s[color[i*m+j]]);
    printf("%d\n%d\n",sum,maxn1);
    int maxn2=0,u,v;
    for(int i=1;i<=n;i++)
    for(int j=1;j<=m;j++)
    {
        c=color[i*m+j],v=color[i*m+j+1],u=color[i*m+j+m];
        if(c!=v&&j!=m)    maxn2=max(maxn2,s[c]+s[v]);
        if(c!=u&& i!=n)    maxn2=max(maxn2,s[c]+s[u]);
    }
    printf("%d\n",maxn2);
    for(int j=1;j<=m;j++)
    for(int i=n;i>=1;i--)
    {
        c=color[i*m+j],v=color[i*m+j+1],u=color[i*m+j-m];
        if(c!=u && s[c]+s[u]==maxn2)    
        {
            printf("%d %d N",i,j);
            return 0;
        }
        if(c!=v && s[c]+s[v]==maxn2)
        {
            printf("%d %d E",i,j);
            return 0;
        }
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/CLGYPYJ/p/7238319.html


http://www.niftyadmin.cn/n/1054405.html

相关文章

Generator 函数和for...of循环,实现斐波那契数列

function* fib () {let [prev, cur] [0,1]for (;;) {yield cur[prev, cur] [cur, curprev]} }for (let item of fib()) {if (item > 1000) break;console.log(item) } 转载于:https://www.cnblogs.com/raind/p/11139054.html

arcanist arc diff 异常 Usage Exception: No changes found.

arc diff提交代码出现异常&#xff1a; You have a saved revision message in .git\arc\create-message. Message begins: 兑换码领取记录表新增字段orderId You can use this message, or discard it. Do you want to use this message? [Y/n] y Linting... No lint engi…

ubuntu环境下安装字体

渲染过程中遇到了字体问题&#xff0c;下面的文章可以很好的解决这个问题。 转自:http://hi.baidu.com/sunorg/item/2c660dc7f04b077ccfd4f862 最省事的方法&#xff1a; 直接把字体复制到~/.fonts文件夹即可。 --------…

图解金山网盾3.6下载保护实现原理

网上下载是2010年电脑病毒******计算机的最主要通道&#xff0c;金山网盾3.6针对病毒***传播的这个特点&#xff0c;创新开发了下载保护模块&#xff0c;拦截病毒***的主渠道&#xff0c;就可以成功阻断病毒***的严重传播。在非典肆虐期间&#xff0c;我们都知道戴口罩可以阻断…

在Ubuntu上安装Intellij IDEA并创建桌面快捷方式

环境信息版本号Ubuntu18.04 LTSIntellij IDEA2019.1.31.首先从官网获取安装包 官方下载地址传送门 然后我就在下载目录下得到了tar.gz的包 2.接下来开始命令行解压安装 2.1 解压缩gzip包 首先,切换工作目录到/usr/local 然后解压当前用户主文件夹/下载/idea压缩包至/usr/local/…

kafka不消费消息

新增一个新的topic&#xff0c;查日子看到消息发送成功&#xff0c;但是没有被消费&#xff0c;检查了代码&#xff0c;发现没有将新topic添加到消费者容器配置中&#xff0c;添加配置信息后就可以消费新topic的消息了。spring.kafka.member.privilege.buy.topic是我新加的topi…

web安全测试之三

1&#xff1a;用户权限测试 &#xff08;1&#xff09;用户权限的控制 a:用户权限控制主要是对一些有权限控制的功能进行验证&#xff1b; b:用户A进行的操作&#xff0c;用户B能否操作&#xff1b; c:用户A有条件的用户才能查看的页面&#xff0c;用户B能否查看&#xff1b;&a…

ArcGIS Editor for OSM

最近连续转了不少GIS方面的文章&#xff0c;没想到GIS在互联网上这么火&#xff0c;连排名都上得很快。转一篇ArcGIS数据方面的文章 转自 http://wiki.openstreetmap.org/wiki/ArcGIS_Editor_for_OSM ArcGIS now has the ability to import and export OSM data via a free add…