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 ...
随机推荐
- Mybatis学习——一对多关联表查询
1.实体类 public class Student { private int id; private String name; } public class Classes { private i ...
- 【转】《APUE》第三章笔记(4)及习题3-2
原文网址:http://www.cnblogs.com/fusae-blog/p/4256794.html APUE第三章的最后面给出的函数,现在还用不着,所以,先留个名字,待到时候用着了再补上好了. ...
- Informatica元数据库解析
Informatica所有的元数据信息均以数据库表的方式存到了元数据库中.当然Infa本身工具提供了很多的人性化的功能,使我们在开发时可以很方便的进行操作,但人们的需求总是万变的,需要方便的取到自己需 ...
- js除法余数
return (Math.round(rs*100)/100); //保保留小数点后两位数: //如果要保留三位则改为:Math.round(rs*1000)/1000; //如果要保留四位则改为:M ...
- 总结c++ primer中的notes
转载:http://blog.csdn.net/ace_fei/article/details/7386517 说明: C++ Primer, Fourth Edition (中英文)下载地址:htt ...
- 关于【bootstrap】中,【tooltip】的不算bug的bug的个人看法
先说下遇到这个问题的背景吧. 就是在页面中有个div,这个div右上角(或者其他位置)有个 × 的图标(这个图标添加tooltip工具提示),光标移到这个图标时,触发tooltip,提示“点击移除”这 ...
- 为什么你写的Python运行的那么慢呢?
大约在一年前,也就是2013年在Waza(地名),Alex Gaynor提到了一个很好的话题:为什么用Python.Ruby和Javascript写的程序总是运行的很慢呢?正如他强调的,关键就是现在出 ...
- 你今天Python了吗?(上)
你今天Python了吗?为了提高你的生产效率,赶快去关注一下小蟒蛇的成长吧!别再把Python当作你的业余爱好了,她能为你做手头上几乎所有的工作,而且能做得更好,也让你把写代码看成是一种真正的乐趣.为 ...
- 2016年VR&AR有市场吗?
新霸哥发现了近期虚拟现实(VR)和增强现实(AR)非常火,已经成为了科技产业中最具前景的技术之一.其实说起这两项技术的应用,人们最容易把它与电子游戏联系在一起,那么在2016年VR&AR有市场 ...
- 【Hadoop代码笔记】Hadoop作业提交之Child启动reduce任务
一.概要描述 在上篇博文描述了TaskTracker启动一个独立的java进程来执行Map任务.接上上篇文章,TaskRunner线程执行中,会构造一个java –D** Child address ...