The Ninth Hunan Collegiate Programming Contest (2013) Problem C
Problem C
Character Recognition?
Write a program that recognizes characters. Don't worry, because you only need to recognize three digits: 1, 2 and 3. Here they are:
.*. *** ***
.*. ..* ..*
.*. *** ***
.*. *.. ..*
.*. *** ***
Input
The input contains only one test case, consisting of 6 lines. The first line contains n, the number of characters to recognize (1<=n<=10). Each of the next 5 lines contains 4n characters. Each character contains exactly 5 rows and 3 columns of characters followed by an empty column (filled with '.').
Output
The output should contain exactly one line, the recognized digits in one line.
Sample Input
3
.*..***.***.
.*....*...*.
.*..***.***.
.*..*.....*.
.*..***.***.
Output for the Sample Input
123
The Ninth Hunan Collegiate Programming Contest (2013) Problemsetter: Rujia Liu Special Thanks: Feng Chen, Md. Mahbubul Hasan
方法很多,深入理解dfs即可方便解决此题 ,我觉得这个方法比较好,有一定的价值。
#include <iostream>
#include <stdio.h>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <stack>
#include <math.h>
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
using namespace std ;
typedef long long LL ; struct Point{
int X ;
int Y ;
Point(){} ;
Point(int x ,int y):X(x),Y(y){} ;
}; char str[][] ;
int N ;
int d[][]={{,},{-,},{,-},{,}} ;
bool visited[][] ;
vector<Point>my_hash[] ; int cango(int x ,int y){
return <=x&&x<=&&<=y&&y<=*N&&str[x][y]=='*';
} void dfs(int x ,int y ,int color){
my_hash[color].push_back(Point(x,y)) ;
visited[x][y]= ;
for(int i=;i<;i++){
int xx=x+d[i][] ;
int yy=y+d[i][] ;
if(cango(xx,yy)&&!visited[xx][yy]){
dfs(xx,yy,color) ;
}
}
} int main(){
int color= ;
scanf("%d",&N) ;
for(int i=;i<=;i++)
scanf("%s",str[i]+) ;
for(int i=;i<=N;i++)
my_hash[i].clear() ;
for(int i=;i<=;i++)
for(int j=;j<=*N;j++){
if(str[i][j]=='*'&&!visited[i][j]){
color++ ;
dfs(i,j,color) ;
}
} for(int i=;i<=N;i++){
Point first = my_hash[i][] ;
Point second = my_hash[i][my_hash[i].size()-] ;
if(first.Y==second.Y&&first.X+==second.X)
putchar('') ;
else if(first.Y<second.Y)
putchar('') ;
else if(first.X+==second.X)
putchar('') ;
}
puts("") ;
return ;
}
The Ninth Hunan Collegiate Programming Contest (2013) Problem C的更多相关文章
- The Ninth Hunan Collegiate Programming Contest (2013) Problem A
Problem A Almost Palindrome Given a line of text, find the longest almost-palindrome substring. A st ...
- The Ninth Hunan Collegiate Programming Contest (2013) Problem F
Problem F Funny Car Racing There is a funny car racing in a city with n junctions and m directed roa ...
- The Ninth Hunan Collegiate Programming Contest (2013) Problem H
Problem H High bridge, low bridge Q: There are one high bridge and one low bridge across the river. ...
- The Ninth Hunan Collegiate Programming Contest (2013) Problem I
Problem I Interesting Calculator There is an interesting calculator. It has 3 rows of button. Row 1: ...
- The Ninth Hunan Collegiate Programming Contest (2013) Problem J
Problem J Joking with Fermat's Last Theorem Fermat's Last Theorem: no three positive integers a, b, ...
- The Ninth Hunan Collegiate Programming Contest (2013) Problem G
Problem G Good Teacher I want to be a good teacher, so at least I need to remember all the student n ...
- The Ninth Hunan Collegiate Programming Contest (2013) Problem L
Problem L Last Blood In many programming contests, special prizes are given to teams who solved a pa ...
- German Collegiate Programming Contest 2013:E
数值计算: 这种积分的计算方法很好,学习一下! 代码: #include <iostream> #include <cmath> using namespace std; ; ...
- German Collegiate Programming Contest 2013:B
一个离散化的简单题: 我用的是STL来做的离散化: 好久没写离散化了,纪念一下! 代码: #include<cstdio> #include<cstring> #include ...
随机推荐
- [原]总结VIM的实用技巧
VIM真是一个神奇而又复杂的编辑器,让我这样的Linux编程新手茫然不已啊.每次到真正动手编程的时候才发现完全不知道该怎么操作VIM,一点都没感觉到VIM的强大,哈哈--正好今天学习了一点VIM操作技 ...
- SSH_框架整合2—查询显示
4. 完成功能. (1)com.atguigu.ssh.actions包下新建EmployeeAction.java package com.atguigu.ssh.actions; import j ...
- Jedis编程设计:连接池
Jedis作为redis的最佳客户端,它提供了连接池的特性,"连接池"在通常情况下可以有效的提高应用的通信能力,并且这是一种良好的设计模式.Jedis的连接池设计基于apa ...
- gridview例子
直接贴代码 MainActivity.java public class MainActivity extends AppCompatActivity { private GridView _grid ...
- MVC:上传文件
今天写了一个使用MVC上传的DEMO,很简单不超过10行代码.代码如下(关注重点,所以尽量精简掉其他代码): 项目结构
- Hadoop学习9--动态增加datanode
http://www.cnblogs.com/ggjucheng/archive/2012/04/18/2454689.html
- Android四:sqllite
1.扩展类SQLiteOpenHelper xxSQLiteHelper extends SQLiteOpenHelper public xxSQLiteHelper(Context context, ...
- DG_Oracle DataGuard Failover主备节点切换(案例)
2014-03-09 Created By BaoXinjian Thanks and Regards
- python实现字体闪图
!/usr/bin/env python from future import print_function import os.path import sys from optparse impor ...
- xpath提取目录下所有标签内的内容,递归 //text()
利用xpath来提取所有标签里面的内容,即使标签头不同 #-*-coding:utf8-*- import re import os from lxml import etree html = ''' ...