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 ...
随机推荐
- Android启动画面实现
每个Android应用程序启动之后都会出现一个Splash启动界面,显示产品LOGO.公司LOGO或者开发者信息.如果应用程序启动时间比较长,那么启动界面就是一个很好的东西,可以让用户耐心等待这段枯燥 ...
- 解决每次打开office 2010显示正在配置的问题
解决每次打开office 2010显示正在配置的问题 OFFICE 2010 MSDN版出来后,下载安装 ,启动后发现每次打开都会出现“正在配置”的进度,删除重装亦不成功,对SETUP.EXE改名也不 ...
- 【转】Dubbo是Alibaba开源的分布式服务框架
Dubbo是Alibaba开源的分布式服务框架,它最大的特点是按照分层的方式来架构,使用这种方式可以使各个层之间解耦合(或者最大限度地松耦合).从服务模型的角度来看,Dubbo采用的是一种非常简单的模 ...
- Perl system(cmd) 和 `cmd` 的区别探讨
在perl中系统调用有两种方式,一种是system(cmd),另一种是`system`以前一直没注意,这两种方式的区别,还以为是一样的,今天写脚本的时候,忽然想要获取命令的返回值,然后,用了my $r ...
- Oracle-decode函数
decode函数 简单例子:管理员登录Oracle select sid, username, decode(command, 0, 'None', 2, 'Insert', 3, 'Select', ...
- 关于Linux中exec的一点心得
最近在学习linux操作系统中的相关知识,在使用execlp系统调用时,发现了些有趣的东西. 首先,关于execlp函数的用法: int execlp(const char *file, const ...
- (C/C++ interview) Static 详解
C Static http://stackoverflow.com/questions/572547/what-does-static-mean-in-a-c-program Static could ...
- Scala第二章学习笔记
最基本的练习~: 使用伴生对象: object holder{ class Foo{ private var x = 5} object Foo{def im_in_yr_foo(f: Foo) = ...
- IREP_SOA Integration SOAP概述(概念)
20150827 Created By BaoXinjian
- python(22)总结下最近遇到的编码问题
最近爬取,或者解析网页是总是遇到编码问题(我的版本:python2.7) 一.常见异常:UnicodeEncodeError: 'ascii' codec can't encode character ...