Exam 1 Character Recognition - Works Application 16

原创 2016年06月08日 20:34:56

Character Recognition

Description

Character recognition is the conversion of images into text. For now we consider each character in the picture is a N*M matrix with only zeros and ones, and we need to recognize K characters. You are to write a program to find minimal number of pixels so that we can recognize each character .For example, we have only two characters ‘T’ and ‘L’, and the matrix size is 3*3, we can think ‘T’ and ‘L’ are 111 100 010 100 010 111 so we can recognize the character with only bottom-left pixel, the answer is 1.

Limits

-Memory limit per test: 256 megabytes
-Time limit per test: The faster the better

Compile & Environment

C++

g++ Main.cc –o Main –fno-asm –Wall –lm –static –std=c++0x –DONLINE_JUDGE

Java

J2SE8
Maximum stack size is 50m

Input

The first line of input is three integers N, M, K(1<=N,M<=10,2<=K<=6). Which represents the size of matrix and number of characters . Then is following K blocks, which represents the matrix. Notice that each block starts with a black line.

Output

You should output the minimum number of pixels, which is the answer.

Sample Test

Input

2 3 2
111
010
100
100

Output

1

Code

#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#define MAX 101
//MAX 取决于 M*N

using namespace std;
vector<vector<int>> arr_num; //用来存放所有的组合可能
vector<string> vec;
int a[MAX] = {0};

//生成组合情况的函数,组合情况保存在arr中
void comb_number(int n, int r){
    if (r == 1){
        a[r - 1] = n;
        int j = 0;
        while (a[j] != 0){
            j++;
        }
        vector<int> tmp;
        for (int  i = j - 1; i >= 0; i--){
            tmp.push_back(a[i]);
        }
        arr_num.push_back(tmp);
    }
    else{
        a[r - 1] = n;
        for (int j = n - 1; j >= r - 1; j--){
            comb_number(j, r - 1);
        }
    }
}

void comb_str(vector<vector<string>> &str,int K){
    for(int i = 0; i < arr_num.size(); i++){
        vector<string> str_tmp;
        for (int j = 0; j < K; j++){
            string tmp;
            for (int m = 0; m < arr_num[0].size(); m++){
                tmp += vec[j][arr_num[i][m]-1];
            }
            str_tmp.push_back(tmp);
        }
        str.push_back(str_tmp);
    }
}

bool judge(vector<vector<string>> &str){
    for (int i = 0; i < str.size();i++){
        int flag = -1;
        vector<string> tmp(str[i]);
        for (int j = 0; j<str[0].size();j++){
            for (int k = 0;k < str[0].size(); k++){
                if (k==j){
                    continue;
                }
                else
                {
                    flag = (tmp[j]).compare(tmp[k]);
                }               
                if (flag == 0)
                    break;
            }
        }
        if (flag == -1)
            return true;
    }
    return false;
}

int main(){
    int N, M, K;
    cin >> N >> M >> K;

    //Input
    while (K--){
        string str;
        for (int i = 0; i<N; i++){
            string tmp;
            cin >> tmp;
            str += tmp;
        }
        vec.push_back(str);  //vec中存有所有字符的表达
    }
    //尝试所有可能 1 到 N*M的长度
    int len = 1;
    for (; len <= N*M; len++){
        arr_num.clear();
        for (int i = N*M; i >= len;i--){
            comb_number(i, len);
        }

        vector<vector<string>> str;
        comb_str(str,vec.size());
        if (judge(str))
            break;  
    }
    cout << len << endl;
    return 0;
}

0152bc39-710d-47f8-8995-bf99b2c21bde

f16aa9ba-64bb-4cf2-879e-a5df7f622134

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

《2006_ICPR_Low Resolution Character Recognition by Image Quality Evaluation》阅读笔记

论文主要思想这是一篇关于低质量字符图像识别的文章,这里的“低质量”指的是字符图像的分辨率低。 作者在文中指出,传统的(指的是2006年之前)低质量字符图像识别方法主要分为两类:第一类方法采用一些图像...

Optical Character Recognition 5.2 released

  • 2014年01月13日 19:36
  • 16.67MB
  • 下载

Character Set Recognition 字符集识别

CharsetFriendlyName 显示名称 Preferred Charset Label 首选字符集标示 Aliases 附加别名 IE Ver 浏览器版本 Min OS 操...

chinese character recognition using Tesseract OCR

I have been using Tesseract 3.0.2 OCR SDK for image text extraction. But if I use chinese text i...
  • yuanya
  • yuanya
  • 2014年08月14日 14:28
  • 3212

Efficient Scene Text Localization and Recognition with Local Character Refinement

论文内容 一、 候选字符提取 1. MSER提取,二值化 2. 算出Distance Map 3. 求出所有SSP(以每个像素为中心的3*3窗口内,若中心点是最大值,则表示是SSP点) 4....

usaco5.4.2 Character Recognition

一 原题 Character Recognition This problem requires you to write a program that performs character re...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Exam 1 Character Recognition - Works Application 16
举报原因:
原因补充:

(最多只允许输入30个字)