链接:https://ac.nowcoder.com/acm/contest/18462/J
来源:牛客网

题目描述

In landscape ecology, one is interested in the connectedness of regions, particularly near shorelines. A fine grid is overlaid on a map or aerial photo and grid squares with land are marked:

Land squares which share an edge are cardinal (North, East, South and West) adjacent (blue lines in the image) and land squares which share an edge or vertex (red and blue lines in the image) are intercardinal adjacent. Write a program which takes as input a marked grid and outputs the total cardinal adjacencies in the grid and the total number of intercardinal adjacencies in the grid.

输入描述:

The input consists of multiple lines. The first line of input contains two space separated decimal integers nrows and ncolumns, (0 < nrows,ncolumns ≤ 1000). This line is followed by nrows additional lines of input each of which contains mcolumns space separated values of 0 or 1. 1 indicates land.

输出描述:

There is one line of output containing two space separated decimal integers: the number of cardinal adjacencies followed by the number of intercardinal adjacencies.

示例1

输入

复制

5 5
1 0 0 1 0
0 1 1 0 1
0 1 0 1 1
1 0 1 1 1
0 1 1 1 1

输出

复制

14 31
#include<iostream>
using namespace std;
const int maxn=1010;
int main(){int n,m;cin>>n>>m;int a[maxn][maxn];for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){cin>>a[i][j];}}int sum1=0;int sum2=0;for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){if(a[i][j]==1){if(a[i+1][j]==1) sum1++;if(a[i-1][j]==1) sum1++;if(a[i][j-1]==1) sum1++;if(a[i][j+1]==1) sum1++;if(a[i-1][j-1]==1) sum2++;if(a[i-1][j+1]==1) sum2++;if(a[i+1][j-1]==1) sum2++;if(a[i+1][j+1]==1) sum2++;a[i][j]=0;}}}cout<<sum1<<" "<<sum2+sum1;
}

J - Cardinal Adjacencies相关推荐

  1. 转: ADO Connection Strings

    Where do you want to connect today?  http://www.connectionstrings.com/default.aspx 原文出处: http://www. ...

  2. 关于Delphi通用涵数

    DELPHI程序注册码设计(转载)     思路是这样的:程序运行时先检测注册表,如果找到注册项,则表明已经注册,如果没有找到注册项,则提示要求注册.         <注册例程>     ...

  3. java.lang.NullPointerException: Attempt to invoke virtual method ‘boolean java.lang.String.equals(j

    今天切正式环境出现的空指针 记录一下 下面是错误 java.lang.NullPointerException: Attempt to invoke virtual method 'boolean j ...

  4. 乌鲁木齐网络赛J题(最小费用最大流模板)

    ACM ICPC 乌鲁木齐网络赛 J. Our Journey of Dalian Ends 2017-09-09 17:24 243人阅读 评论(0) 收藏 举报  分类: 网络流(33)  版权声 ...

  5. html.textboxfor id,How to update the textbox value @Html.TextBoxFor(m = m.MvcGridModel.Rows[j].Id)

    问题 I have problem, that the text box value doesn't get updated with the new value in the model. @Htm ...

  6. MUV LUV EXTRA 2019CCPC秦皇岛站J题 KMP

    题目链接 题意:意思给你俩数一个字符串,然后让你对字符串小数点后边的字符串进行处理,找个一个循环节以及对应出现的长度, 然后用a*p-b*l算得到一个最大值 那肯定循环节就想到了KMP了,然后循环长度 ...

  7. 2018牛客网暑期ACM多校训练营(第十场)J(二分)

    题目描述: 给你n个字符串,要让它们一个一个的合并成一个串.在合并的过程中,要保证被合并的串S是合并后的串r的前缀,模式串t是串r的子序.问你将这n个字符串合并后所得到的字典序最小的串是什么. 题目分 ...

  8. 2016 多校赛3 A 水 B 期望,规律 C 各种博弈 J 物理题,积分 K 暴力,水

    2016 Multi-University Training Contest 3 A - Sqrt Bo 题意:给一个数 n,问n要多少次平方后化为1,如果超过5次输出"TAT". ...

  9. alt+shift+j,添加日期、作者等

    在preference->Java->codestyle->codetemplates->commnets->type 可以编辑如: 1 /** 2 * @author ...

最新文章

  1. (附表设计)不是我吹!超级全面的权限系统设计方案面世了
  2. 查看java源码时出现class文件而不是java文件,可能是因为java的安装路径下没有src.zip文件而是javafx-src.zip文件
  3. 关于:以前的某个程序安装已在安装计算机上创建挂起的文件操作 解决办法
  4. Alamofire源码导读二:发起请求及内部加锁的逻辑
  5. HTML中的节点及其作用
  6. Spring Boot+Ext JS准前后端框架应用的会话(Session)处理
  7. 悦读上品 得乎益友
  8. GoC全教程(附各种下载、教程链接)
  9. 微信小程序做留言板mysql_微信小程序实现留言板(Storage)
  10. WinCC界面中通过插件打开pdf文件
  11. 双路cpu比单路强多少_关于CPU单核单路/双路和双核双路的区别
  12. 大数据十年:Cloudera向左,Palantir向右
  13. 阿里资深架构师的学习之路
  14. 戴尔服务器引导盘装2008,DELL R720服务器安装Windows Server 2008 R2系统的图文详解
  15. 解决IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Pyth
  16. [刷题]剑指offer C++语言刷题-多解法尝试
  17. github这个项目,几行代码生成海报及二维码
  18. 【电商网站】将商品加入购物车代码
  19. CSS实现中英双语导航栏——利用块级元素隐藏实现
  20. 用python计算圆周率_用python计算圆周率π

热门文章

  1. 运用smali自动注入技术分析android应用程序行为
  2. 中国枭龙战机座舱设计远超最新F-16与台风同级
  3. 从ACL2022中看当下NLP热点和最新的有趣工作
  4. WPF 自定义开关按钮实现
  5. C++ Boost库:日期时间库 date_time
  6. 佐藤条码打印机常见问题解决
  7. PHP媒介软文发布开源代码
  8. 【互联网营销基础知识】做电商运营需要掌握什么技能?
  9. Struts2学习笔记__其他表单标签checkboxlist
  10. Springboot的全局异常数据格式处理