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 网络编程--URL互联网资源
1.加入权限 <uses-permission android:name="android.permission.INTERNET"/> 2.Layout设计 < ...
- Servlet Filter 2
10.Filter常见应用 )统一全站字符编码的过滤器 通过配置参数encoding指明使用何种字符编码,以处理Html Form请求参数的中文问题 案例:编写jsp 输入用户名,在Servlet中获 ...
- 10socket编程
这一节主要关注的还是粘包问题,我们利用recv实现一个recv_peek函数,它的目的是偷窥目的,它是利用recv的一个msg_peek参数与read的区别,read读取后 会擦除缓冲区的内容,而re ...
- 【jmeter】参数化User Defined Variables与User Parameters
偶然发现JMeter中有两个元件(User Defined Variables与User Parameters)很相近,刚开始时我也没注意,两者有什么不同.使用时却发现两者使用场景有些不同,现在小结一 ...
- 【linux】 /etc/shadow 文件
格式:username: passwd: lastchg: min: max: warn: inactive: expire: flag 登录名:加密口令:最后一次修改时间:最小时间间隔:最大时间间隔 ...
- MySQL中order by中关于NULL值的排序问题
MySQL中order by 排序遇到NULL值的问题 MySQL数据库,在order by排序的时候,如果存在NULL值,那么NULL是最小的,ASC正序排序的话,NULL值是在最前面的. 如果我们 ...
- VBA相关
--能否彻底隐藏某行或某列 用代码隐藏列,将其放在Private Sub Worksheet_SelectionChange(ByVal Target As Range)Columns(1).Enti ...
- 黄聪:WebBrowser执行和安装jQuery脚本(IEBrowse)
上一文章说明了如何让 js 脚本访问 .NET 中的类, 这次希望给大家说明一下在任意页面中安装 jQuery 脚本, 并操作页面上的元素. 其实在第一篇关于 IEBrowser 的文章当中, 已经有 ...
- 黄聪:C#如何操作JSON数据(读取、分析)
使用开源的类库Newtonsoft.Json(下载地址http://json.codeplex.com/).下载后加入工程就能用.通常可以使用JObject, JsonReader, JsonWrit ...
- AP_AP系列 - 费用报表分析(案例)
2014-07-08 Created By BaoXinjian