很简单的题,就是题意不懂……!

就是判断每个'*'区域内‘X’区域块的个数

WA了好多次,就是太差了;

1.结果排序输出

2.因为是骰子所以不再1-6范围内的数字要舍弃

3.格式要求要空一行……

4.因为碰到X就清零了,所以

XXX*X
XXX*X
.....
X***X
XX***

把X清零之后,在原来的*区域内的dfs就进行不下去了,就wa了……233333333

代码:

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <stack>
#include <cctype>
#include <string>
#include <malloc.h>
#include <queue>
#include <map> using namespace std;
const int INF = 0xffffff;
const double Pi = * atan();
const int Maxn = + ;
//int dir2[8][2] = {{-1,0},{0,-1},{-1,1},{1,-1},{-1,-1},{1,0},{0,1},{1,1}};
int dr[] = {,,,-};
int dc[] = {,,-,};
int h,w;
char graph[][];
int a[];
int cnt;
int num; void dfs2(int r,int c){
graph[r][c] = '#';
for(int i = ;i < ;i++){
int xx = r + dr[i];
int yy = c + dc[i];
if(xx > - && yy > - && xx < h && yy < w){
if(graph[xx][yy] == 'X'){
dfs2(xx,yy);
}
}
}
} void dfs(int r,int c){
if(graph[r][c] == 'X'){
dfs2(r,c);
num++;
}
graph[r][c] = ' ';
for(int i = ;i < ;i++){
int xx = r + dr[i];
int yy = c + dc[i];
if(xx > - && yy > - && xx < h && yy < w){
if(graph[xx][yy] == '*' || graph[xx][yy] == 'X' || graph[xx][yy] == '#')
dfs(xx,yy);
}
}
} int cmp(const void * a,const void * b){
return *((int *)a) - *((int *)b);
} int main()
{
#ifndef ONLINE_JUDGE
freopen("inpt.txt","r",stdin);
#endif
int cas = ;
while(cin >> w >> h){
if(!w && !h)
break;
memset(a,,sizeof(a));
cnt = ;
for(int i = ;i < h;i++)
cin >> graph[i];
for(int i = ;i < h;i++){
for(int j = ;j < w;j++){
if(graph[i][j] == '*' || graph[i][j] == 'X'){
num = ;
dfs(i,j);
if(num > && num < )
a[cnt++] = num;
}
}
}
qsort(a,cnt,sizeof(int),cmp);
cout << "Throw " << ++cas << endl;
for(int i = ;i < cnt-;i++)
cout << a[i] << " ";
cout << a[cnt-] << endl << endl;
}
return ;
}

测试用例:

*.***
***..
.....
.....
..... XXX*X
XXX*X
.....
X***X
XX*** ..........
..X**.*X..
..........
...*X*X...
.......... ..........
..X....X..
..........
...*X*X...
.......... ..........
..X....X..
..X....X..
..XXXXXX..
.......... ..........
..X*X.....
..*X*.....
..X*X.....
.......... ..........
..X*X.....
..*X**....
..X*X*....
.......... XXXXX
XXXXX
XXXXX
XXXXX
XXXXX ..............................
..............................
...............*..............
...*****......****............
...*X***.....**X***...........
...*****....***X**............
...***X*.....****.............
...*****.......*..............
..............................
........***........******.....
.......**X****.....*X**X*.....
......*******......******.....
.....****X**.......*X**X*.....
........***........******.....
.............................. ..........
.XXX......
....XXX...
.......XXX
....XXX...
*X*X...... XXXXX*
.....X
.....X
.....X
.....X
.....X XXXXX.
.....X
.....X
.....X
.....X
.....X XXXXX.
....*X
.....X
.....X
.....X
.....X .....X*X*X*X*X*X***...........
.X......................X.....
...............*.........X....
...X****......****........X...
...*X*.*.....**X***X..........
...*.X......***X**.....XXX....
...*.*X*.....****........X....
...***.X.......*.........X....
..............................
.......X***.............*..***
......******X****.....*X**X*..
..***********......**.*.*.....
.....****X**.......*X**X*.....
........***........*....*.....
........***.********..........

ans:

Throw 

Throw 

Throw 

Throw 

Throw 

Throw 

Throw 

Throw 

Throw 

Throw 

Throw 

Throw 

Throw 

Throw
         

最新文章

  1. 5分钟开启Esper之旅
  2. 新安装loadrunner无法录制脚本的原因之一及解决方案
  3. 认识http协议
  4. Linux操作系统PS命令详细解析
  5. GitHub官方介绍(中文翻译)
  6. 插值和空间分析(二)_变异函数分析(R语言)
  7. 不用外部JAR包,自己实现JSP文件上传!
  8. 免费 Bootstrap 管理后台模块下载
  9. vs2010 条件断点 has changed是什么意思?
  10. ReplaceGoogleCDN:将 Google CDN 更换国家
  11. Android Studio 2.2 新功能详解
  12. 广州.NET微软技术俱乐部提技术问题的正确方式
  13. hbase之认识
  14. border-image属性把边框的背景设置为图片
  15. node.js中fs文件系统模块的使用
  16. Jenkins系列之一——初识
  17. Python 练习:简单的购物车(二)
  18. [svc]linux的ip命令操作接口和路由表
  19. JavaScript--定时器setTimeout()、clearTimeout(var param)和setInterval()、clearInterval(var param)
  20. Hadoop系列之(三):使用Cloudera部署,管理Hadoop集群

热门文章

  1. Net FLow Template
  2. MyEclipse8.5 中安装Spket插件
  3. 关于PsCreateSystemThread函数
  4. qt5_qml_Opengl_shader 第一弹----------------------openglunderqml的简化及介绍
  5. Java字符串排序中文+数字
  6. sizeof与strlen的区别 浅谈
  7. ELK 之一:ElasticSearch 基础和集群搭建
  8. c#与java中byte字节的区别及转换方法
  9. Android学习笔记:进度条ProgressBar的使用以及与AsyncTask的配合使用
  10. mysql启动的四种方式