zoukankan      html  css  js  c++  java
  • uva 11205

     一道暴力子集生成。。 一开始WA看了别人blog后据说是数据中两个int之间的空格可能不止一个。。然后用%d读取

    题目:

     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 teaches algorithms at University, and he has some hours to think while he is running, he has thought up a programming problem which generalizes the problem of his sweat pedometer. The problem consists of obtaining the minimum number of active LEDs necessary to identify each one of the symbols, given a number P of LEDs, and N symbols to be represented with these LEDs (along with the codification of each symbol).

    For example, in the previous sample P = 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), and N 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 of P 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

    2
    7
    10
    1 1 1 0 1 1 1
    0 0 1 0 0 1 0
    1 0 1 1 1 0 1
    1 0 1 1 0 1 1
    0 1 1 1 0 1 0
    1 1 0 1 0 1 1
    1 1 0 1 1 1 1
    1 0 1 0 0 1 0
    1 1 1 1 1 1 1
    1 1 1 1 0 1 1
    6
    10
    0 1 1 1 0 0
    1 0 0 0 0 0
    1 0 1 0 0 0
    1 1 0 0 0 0
    1 1 0 1 0 0
    1 0 0 1 0 0
    1 1 1 0 0 0
    1 1 1 1 0 0
    1 0 1 1 0 0
    0 1 1 0 0 0
    

    Sample Output

    5
    4

    代码

     1 #include <iostream>
     2 #include <cstring>
     3 #include <cstdio>
     4 using namespace std;
     5 
     6 
     7 char B[200][20];
     8 int flag [20] ;
     9 int minn;
    10 int all[200][20];
    11 int subset(int n,int p,int cur)
    12 {
    13     if(cur==p)
    14     {
    15         int ct=0;
    16         for(int i=0;i<p;i++)
    17         {
    18             if(flag[i])
    19             {
    20                 for(int j=0;j<n;j++)
    21                 {
    22                     B[j][ct] = all[j][i]+'0';
    23                 }
    24                 ct++;
    25             }
    26         }
    27         for(int i = 0; i<n; i++)
    28             for(int j=ct;j<p;j++)
    29                 B[i][j] = 0;
    30         for(int j=0;j<n-1;j++)
    31         {
    32             for(int i=j+1;i<n;i++)
    33             {
    34                 if(!strcmp(B[j],B[i]))
    35                     return 0;
    36             }
    37         }
    38 
    39 
    40 
    41         if(minn>ct)
    42         {
    43             minn=ct;
    44         }
    45         return 1;
    46 
    47 
    48     }
    49 
    50     flag [cur ]=0;
    51     subset(n,p,cur+1);
    52     flag[cur]=1;
    53     subset(n,p,cur+1);
    54     return 0;
    55 }
    56 
    57 int main()
    58 {
    59     freopen("in.txt","r",stdin);
    60     int tst;
    61     cin>>tst;
    62     while(tst--)
    63     {
    64         int P,N;
    65         cin>>P>>N;
    66 
    67         for(int i=0;i<N;i++)
    68         {
    69             for(int j=0;j<P;j++)
    70             {
    71                 scanf("%d",&all[i][j]);
    72             }
    73         }
    74         minn=P;
    75 
    76         subset(N,P,0);
    77         cout<<minn<<endl;
    78     }
    79 
    80 
    81     return 0;
    82 }

  • 相关阅读:
    洛谷P1455 搭配购买(并查集)
    洛谷 P2078 朋友(并查集)
    TheZealous的集训日常之 离线算法与在线算法区别
    综合练习: Python自动化测试--从Excel读取数据并录入mysql
    读取excel/CSV/json数据
    Python 日志
    python 操作数据库
    python requests 接口: 调用百度开发者平台图片文字识别接口
    接口测试理论 2
    接口测试理论 1
  • 原文地址:https://www.cnblogs.com/doubleshik/p/3475841.html
Copyright © 2011-2022 走看看