J - Cardinal Adjacencies
链接: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 a 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相关推荐
- 转: ADO Connection Strings
Where do you want to connect today? http://www.connectionstrings.com/default.aspx 原文出处: http://www. ...
- 关于Delphi通用涵数
DELPHI程序注册码设计(转载) 思路是这样的:程序运行时先检测注册表,如果找到注册项,则表明已经注册,如果没有找到注册项,则提示要求注册. <注册例程> ...
- java.lang.NullPointerException: Attempt to invoke virtual method ‘boolean java.lang.String.equals(j
今天切正式环境出现的空指针 记录一下 下面是错误 java.lang.NullPointerException: Attempt to invoke virtual method 'boolean j ...
- 乌鲁木齐网络赛J题(最小费用最大流模板)
ACM ICPC 乌鲁木齐网络赛 J. Our Journey of Dalian Ends 2017-09-09 17:24 243人阅读 评论(0) 收藏 举报 分类: 网络流(33) 版权声 ...
- 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 ...
- MUV LUV EXTRA 2019CCPC秦皇岛站J题 KMP
题目链接 题意:意思给你俩数一个字符串,然后让你对字符串小数点后边的字符串进行处理,找个一个循环节以及对应出现的长度, 然后用a*p-b*l算得到一个最大值 那肯定循环节就想到了KMP了,然后循环长度 ...
- 2018牛客网暑期ACM多校训练营(第十场)J(二分)
题目描述: 给你n个字符串,要让它们一个一个的合并成一个串.在合并的过程中,要保证被合并的串S是合并后的串r的前缀,模式串t是串r的子序.问你将这n个字符串合并后所得到的字典序最小的串是什么. 题目分 ...
- 2016 多校赛3 A 水 B 期望,规律 C 各种博弈 J 物理题,积分 K 暴力,水
2016 Multi-University Training Contest 3 A - Sqrt Bo 题意:给一个数 n,问n要多少次平方后化为1,如果超过5次输出"TAT". ...
- alt+shift+j,添加日期、作者等
在preference->Java->codestyle->codetemplates->commnets->type 可以编辑如: 1 /** 2 * @author ...
最新文章
- (附表设计)不是我吹!超级全面的权限系统设计方案面世了
- 查看java源码时出现class文件而不是java文件,可能是因为java的安装路径下没有src.zip文件而是javafx-src.zip文件
- 关于:以前的某个程序安装已在安装计算机上创建挂起的文件操作 解决办法
- Alamofire源码导读二:发起请求及内部加锁的逻辑
- HTML中的节点及其作用
- Spring Boot+Ext JS准前后端框架应用的会话(Session)处理
- 悦读上品 得乎益友
- GoC全教程(附各种下载、教程链接)
- 微信小程序做留言板mysql_微信小程序实现留言板(Storage)
- WinCC界面中通过插件打开pdf文件
- 双路cpu比单路强多少_关于CPU单核单路/双路和双核双路的区别
- 大数据十年:Cloudera向左,Palantir向右
- 阿里资深架构师的学习之路
- 戴尔服务器引导盘装2008,DELL R720服务器安装Windows Server 2008 R2系统的图文详解
- 解决IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Pyth
- [刷题]剑指offer C++语言刷题-多解法尝试
- github这个项目,几行代码生成海报及二维码
- 【电商网站】将商品加入购物车代码
- CSS实现中英双语导航栏——利用块级元素隐藏实现
- 用python计算圆周率_用python计算圆周率π