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

就是判断每个'*'区域内‘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
         

uva 657的更多相关文章

  1. UVa 657 掷骰子

    意甲冠军:有一个大图.每个像素是格孩子只可能是 . * X 三种.代表背景.玻色子.色子点. 两格子是邻近或在通信,当且仅当两个格儿子*要么X.且具有共同的边,这是上下左右四个方向,斜过,即四连块. ...

  2. UVA 657 The die is cast

      The die is cast  InterGames is a high-tech startup company that specializes in developing technolo ...

  3. UVa 10012 - How Big Is It? 堆球问题 全排列+坐标模拟 数据

    题意:给出几个圆的半径,贴着底下排放在一个长方形里面,求出如何摆放能使长方形底下长度最短. 由于球的个数不会超过8, 所以用全排列一个一个计算底下的长度,然后记录最短就行了. 全排列用next_per ...

  4. uva 1354 Mobile Computing ——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5

  5. UVA 10564 Paths through the Hourglass[DP 打印]

    UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...

  6. UVA 11404 Palindromic Subsequence[DP LCS 打印]

    UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...

  7. UVA&&POJ离散概率与数学期望入门练习[4]

    POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...

  8. UVA计数方法练习[3]

    UVA - 11538 Chess Queen 题意:n*m放置两个互相攻击的后的方案数 分开讨论行 列 两条对角线 一个求和式 可以化简后计算 // // main.cpp // uva11538 ...

  9. UVA数学入门训练Round1[6]

    UVA - 11388 GCD LCM 题意:输入g和l,找到a和b,gcd(a,b)=g,lacm(a,b)=l,a<b且a最小 g不能整除l时无解,否则一定g,l最小 #include &l ...

随机推荐

  1. 由动态库文件dll生成lib库文件(手动生成.def文件,然后使用lib命令编译,非常牛),同理可使用dll生成.a库文件

    本文基于OpenBlas的编译和安装,来说明如何从一个dll文件生成lib库文件. 参考OpenBlas的说明“Howto generate import library for MingW”,和Mi ...

  2. android getDecorView()的作用

    decorView是window中的最顶层view,可以从window中通过getDecorView获取到decorView.通过decorView获取到程序显示的区域,包括标题栏,但不包括状态栏.间 ...

  3. php unset 数组陷阱

    我们删除一个array, unset($arr); 想删除某个元素 unsert($arr[i]) 一个陷阱是: unset() 函数允许删除数组中的某个键.但要注意数组将不会重建索引.如果需要删除后 ...

  4. php下载远程图片方法总结(curl手动解析header)curl跳转问题解决

    常用方法一般有:. file_get_contents file_put_contents readfile($file) //效率很高. 一般代码: /** * 抓取远程图片 * * @param ...

  5. 自定义Log4cpp的日志输出格式

    // 1. 实例化一个PatternLayout对象 log4cpp::PatternLayout* pLayout = new log4cpp::PatternLayout(); // 2. 实例化 ...

  6. 第三方系统打开EAFC的实现

    前言:EAFC是我们公司的一个框架,一个项目上,客户的OA系统要调用我们推送过去的代办任务,希望能打开我们的代办处理界面,我们的代办处理界面是winform的.引出给出了以下的一个方案.在此备存. - ...

  7. java--join方法

    package MyTest; class TestDemo implements Runnable { public void run() { int i = 0; for (int j = 0; ...

  8. Spring MVC视图层:thymeleaf vs. JSP

    本文对比了同一Spring MVC工程中相同页面(一个订阅表单)分别采用Thymeleaf和JSP(包括JSP.JSTL.Spring tag lib)两种方式的实现. 本文的所有代码来自一个可运行的 ...

  9. mysql启动的四种方式

    mysql的四种启动方式: .mysqld 启动mysql服务器:./mysqld --defaults-file=/etc/my.cnf --user=root 客户端连接: mysql --def ...

  10. shell中exec解析(转)

    参考:<linux命令.编辑器与shell编程> <unix环境高级编程> exec和source都属于bash内部命令(builtins commands),在bash下输入 ...