UVA 11205 The broken pedometer
来源:互联网 发布:四五打印助手导入数据 编辑:程序博客网 时间:2024/06/05 06:50
题目如下:
The Broken Pedometer
The Problem
A marathon runner uses a pedometer with which he is having problems. In the pedometer the symbols are represented by seven segments (or LEDs):
But the pedometer does not work properly (possibly the sweat affected the batteries) and only some of the LEDs are active. The runner wants to know if all the possible symbols:
can be correctly identified. For example, when the active LEDs are:
numbers 2 and 3 are seen as:
so they cannot be distinguished. But when the active LEDs are:
the numbers are seen as:
and all of them have a different representation.
Because the runner teachesalgorithms at University, and he has some hours to think while he is running, he has thought up aprogramming problem which generalizes the problem of his sweat pedometer. The problem consists of obtaining the minimum number of active LEDs necessary toidentify each one of the symbols, given a numberP of LEDs, and N symbols to be represented with these LEDs (along with the codification of each symbol).
For example, in the previous sampleP = 7 and N = 10. Supposing the LEDs are numbered as:
The codification of the symbols is: "0" = 1 1 1 0 1 1 1; "1" = 0 0 1 0 0 1 0; "2" = 1 0 1 1 1 0 1; "3" = 1 0 1 1 0 1 1; "4" = 0 1 1 1 0 1 0; "5" = 1 1 0 1 0 1 1; "6" = 1 1 0 1 1 1 1; "7" = 1 0 1 0 0 1 1; "8" = 1 1 1 1 1 1 1; "9" = 1 1 1 1 0 1 1. In this case, LEDs 5 and 6 can be suppressed without losing information, so the solution is 5.
The Input
The input file consists of a first line with the number of problems to solve. Each problem consists of a first line with the number of LEDs (P), a second line with the number of symbols (N), andN lines each one with the codification of a symbol. For each symbol, the codification is a succession of 0s and 1s, with a space between them. A 1 means the corresponding LED is part of the codification of the symbol. The maximum value ofP is 15 and the maximum value of N is 100. All the symbols have different codifications.
The Output
The output will consist of a line for each problem, with the minimum number of active LEDs necessary to identify all the given symbols.
Sample Input
27101 1 1 0 1 1 10 0 1 0 0 1 01 0 1 1 1 0 11 0 1 1 0 1 10 1 1 1 0 1 01 1 0 1 0 1 11 1 0 1 1 1 11 0 1 0 0 1 01 1 1 1 1 1 11 1 1 1 0 1 16100 1 1 1 0 01 0 0 0 0 01 0 1 0 0 01 1 0 0 0 01 1 0 1 0 01 0 0 1 0 01 1 1 0 0 01 1 1 1 0 01 0 1 1 0 00 1 1 0 0 0
Sample Output
54
这道题要求找出最少的列数,使得这些列可以完全区分所有行。首先需要求出列的所有组合,通过枚举列的位置集合的所有子集可以实现。而求子集可以用位向量法。对于每个情况,将对应的行的数据按列复制到一个辅助数组中,看这个辅助数组是否所有行均不相同,辅助数组设置为字符数组更好判断是否相同。用Min变量记录所有情况中列数最少的。
AC的代码如下:
- UVa 11205 The broken pedometer
- uva 11205 - The broken pedometer
- uva 11205 - The broken pedometer
- UVa 11205 - The broken pedometer
- uva 11205 - The broken pedometer
- UVa 11205 - The broken pedometer
- UVA 11205 The broken pedometer
- uva 11205 The Broken Pedometer
- uva 11205 The broken pedometer
- uva 11205 - The broken pedometer
- UVa 11205 - The broken pedometer
- UVA 11205 The broken pedometer
- UVa 11205 - The broken pedometer
- UVA 11205 - The broken pedometer
- UVa-11205-The broken pedometer
- UVA - 11205 The broken pedometer
- UVA - 11205 The broken pedometer
- uva 11205 The broken pedometer
- codeforce 445B 并查集
- 2.2.2Data Access/Integration
- leetcode: Merge Sorted Array
- Android中使用CountDownLatch并发多线程操作
- Keil C 中全局变量的使用
- UVA 11205 The broken pedometer
- Java NIO系列教程(七) FileChannel
- 实战域树部署,Active Directory系列之十九
- 华为(5)单词倒排
- 自旋锁、排队自旋锁、MCS锁、CLH锁
- Python: Windows下pip的安装及简单应用
- cs61a课程总结 lecture4
- 使用depot_tools下载chromium源码
- java JDK源码和API的初步了解