uva 657
2024-10-18 23:28:11
很简单的题,就是题意不懂……!
就是判断每个'*'区域内‘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
最新文章
- 5分钟开启Esper之旅
- 新安装loadrunner无法录制脚本的原因之一及解决方案
- 认识http协议
- Linux操作系统PS命令详细解析
- GitHub官方介绍(中文翻译)
- 插值和空间分析(二)_变异函数分析(R语言)
- 不用外部JAR包,自己实现JSP文件上传!
- 免费 Bootstrap 管理后台模块下载
- vs2010 条件断点 has changed是什么意思?
- ReplaceGoogleCDN:将 Google CDN 更换国家
- Android Studio 2.2 新功能详解
- 广州.NET微软技术俱乐部提技术问题的正确方式
- hbase之认识
- border-image属性把边框的背景设置为图片
- node.js中fs文件系统模块的使用
- Jenkins系列之一——初识
- Python 练习:简单的购物车(二)
- [svc]linux的ip命令操作接口和路由表
- JavaScript--定时器setTimeout()、clearTimeout(var param)和setInterval()、clearInterval(var param)
- Hadoop系列之(三):使用Cloudera部署,管理Hadoop集群
热门文章
- Net FLow Template
- MyEclipse8.5 中安装Spket插件
- 关于PsCreateSystemThread函数
- qt5_qml_Opengl_shader 第一弹----------------------openglunderqml的简化及介绍
- Java字符串排序中文+数字
- sizeof与strlen的区别 浅谈
- ELK 之一:ElasticSearch 基础和集群搭建
- c#与java中byte字节的区别及转换方法
- Android学习笔记:进度条ProgressBar的使用以及与AsyncTask的配合使用
- mysql启动的四种方式