Codeforces GYM 100114 B. Island 水题
B. Island
Time Limit: 1 Sec
Memory Limit: 256 MB
题目连接
http://codeforces.com/gym/100114
Description
On February 30th this year astronauts from the International Space Station flew over the Pacific Ocean and took a picture, on which was discovered a previously unknown island. On the digitized picture the island appears as a connected set of square cells. This means that someone can reach some cell of land from some other cell land, going from cell to cell through their common side. There is no other water area within the island. The island is surrounded by water. The coastline of the island is a closed polygonal line. The water cell are marked by minus sign ("–"), and the land cell – by plus sign ("+"). The coastline cell is a cell, which have a common border with water cell. In the figure below the length of the coastline is 14 cells. The other five cells of land are internal cells of the island. Write a program that, given dimensions of the rectangle n and m and digitized picture, calculates l – the number of cells that form the coastline of the island.
Input
Output
Sample Input
7 8 –––––––– –––+++–– –––+++–– –+++++–– –+++++–– ––++–+–– --------
Sample Output
HINT
题意
给你一个岛屿,问你他的边界有多长
题解:
对于一个点,只要他周围有一个点是海,那么这个点就是边界
代码:
//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <bitset>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 510000
#define mod 10007
#define eps 1e-9
int Num;
//const int inf=0x7fffffff; //§ß§é§à§é¨f§³
const int inf=0x3f3f3f3f;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************** string s[];
int vis[][];
int dx[]={,-,,};
int dy[]={,,,-};
struct node
{
int x,y;
};
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
//input.txt / output.txt
int n=read(),m=read();
node st;
for(int i=;i<n;i++)
cin>>s[i];
int ans=;
int flag=;
for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
{
if(s[i][j]=='+')
{
int flag=;
for(int k=;k<;k++)
{
if(i+dx[k]<||i+dx[k]>=n)
flag=;
else if(j+dy[k]<||j+dy[k]>=m)
flag=;
else if(s[i+dx[k]][j+dy[k]]=='-')
flag=;
}
if(flag)
ans++;
}
}
}
printf("%d\n",ans);
}
Codeforces GYM 100114 B. Island 水题的更多相关文章
- Codeforces Gym 100286G Giant Screen 水题
Problem G.Giant ScreenTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/con ...
- Codeforces gym 100685 C. Cinderella 水题
C. CinderellaTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/C ...
- Codeforces Gym 100431D Bubble Sort 水题乱搞
原题链接:http://codeforces.com/gym/100431/attachments/download/2421/20092010-winter-petrozavodsk-camp-an ...
- Codeforces Gym 100114 A. Hanoi tower 找规律
A. Hanoi tower Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descript ...
- codeforces GYM 100114 J. Computer Network 无相图缩点+树的直径
题目链接: http://codeforces.com/gym/100114 Description The computer network of “Plunder & Flee Inc.” ...
- codeforces GYM 100114 J. Computer Network tarjan 树的直径 缩点
J. Computer Network Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Des ...
- Codeforces Gym 100114 H. Milestones 离线树状数组
H. Milestones Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descripti ...
- Codeforces GYM 100114 D. Selection 线段树维护DP
D. Selection Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descriptio ...
- Codeforces GYM 100114 C. Sequence 打表
C. Sequence Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Description ...
随机推荐
- 【原】cocos2d-x 2.0.4 不支持https协议 CURLE_UNSUPPORTED_PROTOCOL
我们项目组用的cocos2d-x版本还比较老,各种好的功能不能用. 今天就让我遇到一个问题,使用CCHttpClient发送http请求的时候,https协议的不支持,返回失败信息如下 errorco ...
- 对Spring IoC容器实现的结构分析
本文的目标:从实现的角度来认识SpringIoC容器. 观察的角度:从外部接口,内部实现,组成部分,执行过程四个方面来认识SpringIoC容器. 本文的风格:首先列出SpringIoC的外部接口及内 ...
- 国外主流PHP框架比较
最近简单的使用了目前在国内用的比较多的几个主流国外PHP框架(不包括国内框架),大致对这些框架有个直观上的感受,简单分享一下,对于哪些做框架选型的时候,权当一个参考. 主要参考的框架包括:CodeIg ...
- hashCode之一--两个对象值相同,有相同的hash code
两个对象值相同(x.equals(y) == true),则一定有相同的hash code. 这是java语言的定义: 因为:Hash,一般翻译做“散列”,也有直接音译为"哈希" ...
- storm入门教程 第四章 消息的可靠处理【转】
4.1 简介 storm可以确保spout发送出来的每个消息都会被完整的处理.本章将会描述storm体系是如何达到这个目标的,并将会详述开发者应该如何使用storm的这些机制来实现数据的可靠处理. 4 ...
- Linux基本命令(4)有关关机和查看系统信息的命令
有关关机和查看系统信息的命令 命令 说明 shutdown 正常关机 reboot 重启计算机 ps 查看目前程序执行的情况 top 查看目前程序执行的情景和内存使用的情况 kill 终止一个进程 d ...
- 给Webkit内核的浏览器控件增加互交功能
转载请说明出处,谢谢~~ 昨天封装了基于webkit的wke浏览器内核,做成了duilib的浏览器控件,实现了浏览功能,但是单单的浏览功能还不满足需求,在我的仿酷狗项目中乐库的功能需要与浏览器互交. ...
- C++ 编程输入输出语句
C++ 的标准输入.输出就是我们已经使用的包含头文件iostream,他不但提供了I/O的库函数,也提供了使用该库的流模式,从cin>> 流入 和cout<<流出到设备就是一 ...
- jq实现图片轮播:圆形焦点+左右控制+自动轮播
来源:http://www.ido321.com/862.html html代码: 1: <!DOCTYPE html> 2: <html lang="en"&g ...
- wireshark http过程
一直研究lighttpd源码,顺便看下网络编程,不说太多,开始吧 第一步 设置wireshark过滤规则 tcp.port eq 81 ,然后开始捕捉 第二步 http://183.61.16.16 ...