uva 657

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

就是判断每个‘*‘区域内‘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 = 4 * atan(1);
const int Maxn = 200 + 10;
//int dir2[8][2] = {{-1,0},{0,-1},{-1,1},{1,-1},{-1,-1},{1,0},{0,1},{1,1}};
int dr[] = {0,1,0,-1};
int dc[] = {1,0,-1,0};
int h,w;
char graph[60][60];
int a[2500];
int cnt;
int num;

void dfs2(int r,int c){
    graph[r][c] = ‘#‘;
    for(int i = 0;i < 4;i++){
        int xx = r + dr[i];
        int yy = c + dc[i];
        if(xx > -1 && yy > -1 && 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 = 0;i < 4;i++){
        int xx = r + dr[i];
        int yy = c + dc[i];
        if(xx > -1 && yy > -1 && 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 = 0;
    while(cin >> w >> h){
        if(!w && !h)
            break;
        memset(a,0,sizeof(a));
        cnt = 0;
        for(int i = 0;i < h;i++)
            cin >> graph[i];
        for(int i = 0;i < h;i++){
            for(int j = 0;j < w;j++){
                if(graph[i][j] == ‘*‘ || graph[i][j] == ‘X‘){
                    num = 0;
                    dfs(i,j);
                    if(num > 0 && num < 7)
                        a[cnt++] = num;
                }
            }
        }
        qsort(a,cnt,sizeof(int),cmp);
        cout << "Throw " << ++cas << endl;
        for(int i = 0;i < cnt-1;i++)
            cout << a[i] << " ";
        cout << a[cnt-1] << endl << endl;
    }
    return 0;
}

测试用例:

5 5
*.***
***..
.....
.....
.....
5 5
XXX*X
XXX*X
.....
X***X
XX***
10 5
..........
..X**.*X..
..........
...*X*X...
..........
10 5
..........
..X....X..
..........
...*X*X...
..........
10 5
..........
..X....X..
..X....X..
..XXXXXX..
..........
10 5
..........
..X*X.....
..*X*.....
..X*X.....
..........
10 5
..........
..X*X.....
..*X**....
..X*X*....
..........
5 5
XXXXX
XXXXX
XXXXX
XXXXX
XXXXX
30 15
..............................
..............................
...............*..............
...*****......****............
...*X***.....**X***...........
...*****....***X**............
...***X*.....****.............
...*****.......*..............
..............................
........***........******.....
.......**X****.....*X**X*.....
......*******......******.....
.....****X**.......*X**X*.....
........***........******.....
..............................
10 6
..........
.XXX......
....XXX...
.......XXX
....XXX...
*X*X......
6 6
XXXXX*
.....X
.....X
.....X
.....X
.....X
6 6
XXXXX.
.....X
.....X
.....X
.....X
.....X
6 6
XXXXX.
....*X
.....X
.....X
.....X
.....X
30 15
.....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*.....
........***........*....*.....
........***.********..........
0 0

ans:

Throw 1
0

Throw 2
2 2

Throw 3
1 1 2

Throw 4
1 1 2

Throw 5
1

Throw 6
5

Throw 7
5

Throw 8
1

Throw 9
1 2 2 4

Throw 10
1 1 1 1 2

Throw 11
2

Throw 12
1 1

Throw 13
2

Throw 14
1 1 1 1 1 2 3 4 5 6
时间: 2024-11-08 10:05:04

uva 657的相关文章

uva 657 - The die is cast

  The die is cast  InterGames is a high-tech startup company that specializes in developing technology that allows users to play games over the Internet. A market analysis has alerted them to the fact that games of chance are pretty popular among the

UVa 657 掷色子

题意:就是有一张大图,每个像素即格子只可能是 . * X 三种,分别代表背景.色子.色子的点数.两个格子是相邻的或连通的,当且仅当两个格子是*或X,且有公共边,即上下左右四个方向,对角不算,即四连块.将一个连通块看做一个色子,将这个连通块中的X的连通块个数看做该色子的点数. 思路:两次深搜.第一次是由*和X来深搜每个连通块,在深搜每个连通块时由X来深搜X的连通块个数.这里可以通过两个标记数组visit来表示是否访问过,visitx来表示是否访问深搜X过.(也可以将X改为*.*改为.的方式实现,不

UVa 657 掷骰子

意甲冠军:有一个大图.每个像素是格孩子只可能是 . * X 三种.代表背景.玻色子.色子点. 两格子是邻近或在通信,当且仅当两个格儿子*要么X.且具有共同的边,这是上下左右四个方向,斜过,即四连块. 个色子.将这个连通块中的X的连通块个数看做该色子的点数. 思路:两次深搜.第一次是由*和X来深搜每一个连通块.在深搜每一个连通块时由X来深搜X的连通块个数.这里能够通过两个标记数组visit来表示是否訪问过,visitx来表示是否訪问深搜X过.(也能够将X改为*.*改为.的方式实现,不用标记数组.之

uva 10012 How Big Is It?(枚举)

uva 10012 How Big Is It? Ian's going to California, and he has to pack his things, including his collection of circles. Given a set of circles, your program must find the smallest rectangular box in which they fit. All circles must touch the bottom o

UVA 562 Dividing coins --01背包的变形

01背包的变形. 先算出硬币面值的总和,然后此题变成求背包容量为V=sum/2时,能装的最多的硬币,然后将剩余的面值和它相减取一个绝对值就是最小的差值. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; #define N 50007 int c[102],d

UVA 10341 Solve It

Problem F Solve It Input: standard input Output: standard output Time Limit: 1 second Memory Limit: 32 MB Solve the equation: p*e-x + q*sin(x) + r*cos(x) + s*tan(x) + t*x2 + u = 0 where 0 <= x <= 1. Input Input consists of multiple test cases and te

UVA 11014 - Make a Crystal(容斥原理)

UVA 11014 - Make a Crystal 题目链接 题意:给定一个NxNxN的正方体,求出最多能选几个整数点.使得随意两点PQ不会使PQO共线. 思路:利用容斥原理,设f(k)为点(x, y, z)三点都为k的倍数的点的个数(要扣掉一个原点O).那么全部点就是f(1),之后要去除掉共线的,就是扣掉f(2), f(3), f(5)..f(n).n为素数.由于这些素数中包括了合数的情况,而且这些点必定与f(1)除去这些点以外的点共线,所以扣掉.可是扣掉后会扣掉一些反复的.比方f(6)在f

[UVa] Palindromes(401)

UVA - 401 Palindromes Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description A regular palindrome is a string of numbers or letters that is the same forward as backward. For example, the string "ABCDED

uva 401.Palindromes

题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=342 题目意思:给出一段字符串(大写字母+数字组成).判断是否为回文串 or 镜像串 or 回文镜像串 or 什么都不是.每个字母的镜像表格如下 Character Reverse Character Reverse Character Reverse A A M M Y Y B