ACM PKU 1111 Image Perimeters http://acm.pku.edu.cn/JudgeOnline/problem?id=1111
广搜永远记住,下标不要错,COPY时一定要记得改下标:
#include <iostream>
#include <queue>
using namespace std;char rec[21][21];
bool flag[21][21];int h[8] = {1,1,1,0,0,-1,-1,-1};
int s[8] = {1,-1,0,-1,1,0,-1,1};int row,column,st0,st1;
int sum = 0;struct node
{int r;int c;node(){};node(int x , int y){r = x ;c = y;};
};queue<node>myqueue;int temp(int x,int y)
{int num = 0;if (x == 0 ||rec[x-1][y]== '.')num++;if (x == row-1 ||rec[x+1][y]== '.')num++;if (y == 0 ||rec[x][y-1]=='.')num++; if (y == column-1 ||rec[x][y+1]=='.')num++;return num;
}bool charge (int H,int L)
{if( (H >=0) && (H < row) && (L >= 0) && (L < column))if ((rec[H][L]=='X') && (flag[H][L] == 0) )return true;return false;
}void solve(int H, int L)
{ if (charge(H,L)){flag[H][L] = 1;sum += temp(H,L);myqueue.push(node(H , L));rec[H][L] = '1';}while (!myqueue.empty()){int i ;for(i = 0 ;i < 8 ; i++){int a = myqueue.front().r;int b = myqueue.front().c;if(charge(myqueue.front().r + h[i] ,myqueue.front().c + s[i])){myqueue.push(node(myqueue.front().r + h[i] , myqueue.front().c + s[i]));rec[myqueue.front().r + h[i]][myqueue.front().c + s[i]] = '1';sum += temp(myqueue.front().r + h[i],myqueue.front().c + s[i]);}}myqueue.pop();}
} int main ()
{while (cin>>row>>column>>st0>>st1){int i, j;memset(flag,0,sizeof (flag));sum = 0;if (row==0 && column==0 && st0==0 && st1==0 ) break;for (i=0; i<row; i++)for (j=0; j<column;j++)cin >> rec[i][j];solve(st0-1,st1-1) ;cout<< sum << endl;}return 0;
}
转载于:https://www.cnblogs.com/Chinese-Coder-Clarence/articles/2039255.html
ACM PKU 1111 Image Perimeters http://acm.pku.edu.cn/JudgeOnline/problem?id=1111相关推荐
- ACM 1740 A New Stone Game http://acm.pku.cn/JudgeOnline/problem?id=1740
题目大意:有N堆石头,每堆石头数目在1到100之间,最多有10堆.两人分别取走石头.取石头的规则是:每次只能从1堆中取,每次取走至少1个.取过后还可以把这堆的石头任意分配到其它堆上(这些堆必须有石头, ...
- PKU ACM 1258 Agri-Net http://acm.pku.edu.cn/JudgeOnline/problem?id=1258
熟悉了prim算法后这样的题目在十分钟内真的可以解决!最小生成树,prim真的很有用! #include <iostream> using namespace std; const int ...
- Biorhythms ACM PKU http://acm.pku.cn/JudgeOnline/problem?id=1006
本题可以参考Wikipedia上线性同余同方程的解法,方法很简单手算一会就出来了.也可以参考中国同余定理:就这么多,下面我展示我的代码:#include <iostream> using ...
- pku acm 2140 Herd Sums http://acm.pku.edu.cn/JudgeOnline/problem?id=2140
2140代码短小精悍:#include<stdio.h> int main() { int cnt=0,i; long s; scanf("%ld",&s); ...
- ACM PKU 2663 Tri Tiling http://acm.pku.edu.cn/JudgeOnline/problem?id=2663
这题开始没有思路,后来看了流牛的解题报告才写出来: 递推公式我写一下: sign[i] = 1 (当i == 0 时,具体为什么我也没有具体的说明方法 ...
- ACM PKU 2559 Largest Rectangle in a Histogram http://acm.pku.edu.cn/JudgeOnline/problem?id=2559
关于覆盖,用DP是一种很不错的解决方法,时效也很不错.... 这题目把图一画就很明确了,没有说明的必要了. #include <iostream> using namespace std; ...
- ACM PKU 1019 Number Sequence http://acm.pku.edu.cn/JudgeOnline/problem?id=1019
#include <iostream> #include <cmath> using namespace std;int Len(int n) // 求数字的长度函数: {re ...
- Hansel and Grethel ACM pku http://acm.pku.cn/JudgeOnline/problem?id=1254
1254是一道非常简单的关于平面直线相交问题的计算,只要注意一点: 斜率并不是所给出的指南针上的度数而应该是(90-degree):解决了此问题后所有的问题都迎刃而解了 我的代码如下: #includ ...
- acm c语言指针,c语言 ACM一道 很简单的
匿名用户 1级 2008-12-04 回答 主要还是在于算法,计算机语言倒不是多重要,C语言和C++都是可以的 美国计算机协会 ACM(Association for Computing Machin ...
最新文章
- AngularJS开发指南7:AngularJS本地化,国际化,以及兼容IE低版本浏览器
- Build failed in step 'Installing CLooG for host'
- python理论知识选择题_Python基础自测题答案和基础知识梳理
- [Codeforces673A]Bear and Game(水题,思路)
- SAS笔记(2) RETAIN语句
- UNITY关于阴影打开关闭的设置
- js学习 字符串常用方法
- VS2005、VS2010等VS系列IDE在MFC开发过程中,Resource View标签打不开,问题为“opened in other editor”
- 2021年中国以太网测试设备市场趋势报告、技术动态创新及2027年市场预测
- 提示编码有问题时,VS保存选项
- 指定selenium chrome下载文件路径
- [MATLAB]数值计算
- php架构师都会有什么面试题,PHP架构师面试题目和答案
- JavaWeb企业在线文档管理系统
- 阿里云服务器ddos攻击防御
- ThinkPHP整合微信支付之发裂变红包
- 不求人小白也能搭建私有云盘,焕然一新体验
- 第二十三章 宋桓公自行其是讨苦吃 齐桓公连克宋郑震东方
- 复选框的对勾颜色怎么改
- 数据库中文mybatis连接mysql数据库插入中文乱码