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

就是判断每个'*'区域内‘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. Week6(10月14日)

    Part I:提问  =========================== 1.什么是视图模型?2.我们在留言本中,加入了一个怎样的视图模型?如何处理它? Part II:Ch05 视图模型 === ...

  2. 基于visual Studio2013解决C语言竞赛题之0502最小数替换

         题目

  3. W5100使用中的常见问题

    来自:成都浩然 越来越多的嵌入式网络系统project师喜欢上了W5100,它集TCP/IP协议栈.以太网的MAC和PHY一体,不仅使系统性能得到非常大的提升,也给产品开发工作带来极大的方便.随着W5 ...

  4. quartz群调查调度机制和源代码分析

    pageId=85056282#quartz集群调度机制调研及源代码分析-quartz2.2.1集群调度机制调研及源代码分析" style="color:rgb(59,115,17 ...

  5. [转载]IOS项目打包除去NSLog和NSAssert处理之阿堂教程

    原文链接地址:http://blog.sina.com.cn/s/blog_81136c2d0102v1ck.html 原文地址:IOS项目打包除去NSLog和NSAssert处理之阿堂教程作者:时空 ...

  6. JVM --java 字节码的结构解析

    Java字节码文件的主体结构分为一下几个部分:Class文件头部.常量池区域.当前类的描述信息.字段列表.方法列表.属性列表. Class文件头部 任何的class文件的前四个字节的内容就是CA FE ...

  7. JAVA之等号、传类对象参数与c++的区别

    在JAVA中用等号对类对象进行赋值,实际上操作的是对象的地址. eg: package MyText; class ClassA { int value; public void seta(int v ...

  8. java list三种遍历方法性能比较

    从c/c++语言转向java开发,学习java语言list遍历的三种方法,顺便测试各种遍历方法的性能,测试方法为在ArrayList中插入1千万条记录,然后遍历ArrayList,发现了一个奇怪的现象 ...

  9. CSharp Algorithm - Replace multiplication operator with a method

    /* Author: Jiangong SUN */ How to replace multiplication operation with a method? For example, you h ...

  10. 关于UIText换行

    话不多说,直接上代码 --代码是lua的,c++也一样 local text = ccui.Text:create("text can line wrap text can line wra ...