zoukankan      html  css  js  c++  java
  • HUT1558 Count Cycles

    1558: Count Cycles

    Time Limit: 1 Sec  Memory Limit: 128 MB
    Submit: 84  Solved: 21
    [Submit][Status][Web Board]

    Description

    In information theory, a low-density parity-check (LDPC) code is a linear error correcting code, a method of transmitting a message over a noisy transmission channel, and is constructed using a sparse bipartite graph. LDPC codes are capacity-approaching codes, which means that practical constructions exist that allow the noise threshold to be set very close (or even arbitrarily close on the BEC) to the theoretical maximum (the Shannon limit) for a symmetric memory-less channel.

    LDPC codes are defined by a sparse parity-check matrix. This parity-check matrix is often randomly generated and the elements in it are 0 or 1. If we want use LDPC codes, we should make the parity-check matrix have no cycles. When four vertices of the rectangle in the matrix are 1, we say that the matrix has one cycle. Now we want to know how many cycles are in the matrix.

    For a given matrix, you are to count the number of cycles in the matrix.

    Input

    There are several test cases, each test case starts with a line containing two positive integers M and N. M and N is the size of the matrix (1<=M<=100, 1<=N<=100). Next follow a matrix which contains only number 0 and 1. The input will finish with the end of file.

    Output

               For each the case, your program will output the number of cycles in the given matrix on separate line.

    Sample Input

    1 3
    1 1 1
    2 3
    1 0 1
    0 1 1
    3 3
    1 0 1
    0 1 1
    1 1 1

    Sample Output

    0
    0
    2

      这题是要我们找出所给矩阵中有多少个四个点都为1的矩阵。思路是这样的,首先选取行列中较小的一个,然后定义两个指针进行组合,以第三个数据进行说明,这里行列相等,就假设选取了列,那么首先第一列和第二列组合,看这两列下面的有多少行满足有都为1的两点,统计完之后,那么最和的矩阵数就是一个1+2+3+... 的问题了,后面再1/3列组合,2/3列组合。
      代码如下:
    #include <cstdio>
    #include <cstring>
    #include <iostream>
    using namespace std;
     
    char map[105][105];
     
    int main(  )
    {
        int N, M;
        while( scanf( "%d %d", &N, &M )!= EOF )
        {
            for( int i= 1; i<= N; ++i )
            {
                for( int j= 1; j<= M; ++j )
                {
                    char c;
                    while( c= getchar() )
                    {
                        if( c== '0'|| c== '1' )
                        {
                            map[i][j]= c;
                            break;
                        }
                    }
                }
            } 
            int ans= 0;
            if( M<= N )
            {
                for( int i= 1; i< M; ++i )
                {
                    for( int j= i+ 1; j<= M; ++j )
                    {
                        int cnt= 0;
                        for( int k= 1; k<= N; ++k )
                        {
                            if( map[k][i]== '1'&& map[k][j]== '1' )
                            {
                                cnt++;
                            }
                        }
                        ans+= ( cnt* ( cnt- 1 ) )/ 2;
                    }
                }
            }
            else
            {
                for( int i= 1; i< N; ++i )
                {
                    for( int j= i+ 1; j<= N; ++j )
                    {
                        int cnt= 0;
                        for( int k= 1; k<= M; ++k )
                        {
                            if( map[i][k]== '1'&& map[j][k]== '1' )
                            {
                                cnt++;
                            }
                        }
                        ans+= ( cnt* ( cnt- 1 ) )/ 2;
                    }
                }
            }
            printf( "%d\n", ans );
        }
        return 0;
    }
    
  • 相关阅读:
    关于宏定义与内联函数
    vsv
    nginx与php之间的通信
    php高级
    PHP基础知识
    php结合redis实现高并发下的抢购、秒杀功能
    MySQL索引优化
    PHP基础(谈一谈Session&Cookie)
    Yii2框架查询指定字段和获取添加数据的id
    linux常用命令
  • 原文地址:https://www.cnblogs.com/Lyush/p/2125439.html
Copyright © 2011-2022 走看看