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 ...
随机推荐
- 会话控制:SESSION,COOKIE
1.http协议: HTTP—超文本传输协议,在TCP协议(长连接.像一个硬件)基础上; 特点:短连接,无状态协议,没法记录本次连接的状态;适用于静态页面的访问,对于后期某些页面是需要浏览器预知客户信 ...
- php计算字符串长度:utf8编码,包含中文
php计算字符串长度:utf8编码 中文当作1个字符处理(strlen默认当作两个字符) 上函数: /** * 计算 UTF-8 字符串长度 * * @param string $str * @ret ...
- erlang的shell历史记录
erlang的shell默认重启以后木有历史记录,略蛋疼,开发的时候略不便 网上找了个方式 sudo apt-get install rlwrap vim ~/.bash_profile alias ...
- 修改mongodb oplog size
转载地址:http://blog.csdn.net/huwei2003/article/details/43307647 修改mongodb oplog size oplog简介: oplog:ope ...
- 【wp之二 页面布局】
1. panoramic全景视图 新建工程选择:Windows Phone Panorama Application 相当于用放大镜看报纸的感觉.用一张图片作为背景. 2.pivot透视视图
- ASP.NET MVC 基础(01)
[ASP.NET MVC ]系列文章大致会包含这样一些内容: 1.ASP.NET MVC 的一些高级知识点: 2.ASP.NET MVC 的一些最新技术: 3.ASP.NET MVC 网站安全方面的知 ...
- ADO.NET(查询、属性扩展)
一.ADO.NET 融合面向对象的查询语句 1.只查询一条数据 //数据访问中的select方法 public stu select(string xuehao) { stu s = null; cm ...
- bug_ _java.lang.IllegalArgumentException: View not attached to window manager 2
今天遇到一个很奇特的问题,当用户设置了PIN码,在锁屏界面正常解锁PIN码后,进入Launcher时显示com.android.phone 已停止运行.一开始猜想会不会是解锁PIN码的时候处理导致了P ...
- ylbtech-LanguageSamples-Threading(线程处理)
ylbtech-Microsoft-CSharpSamples:ylbtech-LanguageSamples-Threading(线程处理) 1.A,示例(Sample) 返回顶部 “线程处理”示例 ...
- android实现 服务器功能
package com.weijia.tests; import java.io.IOException; import java.net.InetSocketAddress; import java ...