博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HUT-1558 Count Cycles
阅读量:7174 次
发布时间:2019-06-29

本文共 3204 字,大约阅读时间需要 10 分钟。

1558: Count Cycles

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

Description

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

LDPC codes are defined by a sparse . This is often randomly generated and the elements in it are 0 or 1. If we want use LDPC codes, we should make the 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 
#include
#include
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;}

转载于:https://www.cnblogs.com/Lyush/archive/2011/08/02/2125439.html

你可能感兴趣的文章
群雄逐鹿的移动互联网时代【转载】
查看>>
【排序】InsertSort
查看>>
[c++11]多线程编程(五)——unique_lock
查看>>
漫谈promise使用场景
查看>>
Design Pattern的万剑归宗 => Mediator
查看>>
Javascript中的原型继承的一些看法与见解
查看>>
HackerRank:JavaScript 是最知名的编程语言
查看>>
Linux修改本地时间
查看>>
elasticsearch字符串包含查询
查看>>
5- Flask构建弹幕微电影网站-项目分析、搭建目录及模型设计
查看>>
Mysql四种常见数据库引擎
查看>>
《Kotin 极简教程》第7章 面向对象编程(OOP)(1)
查看>>
Chrome吃内存的能力可不是说着玩的!
查看>>
iStaing获500万美元投资,VR室内设计离我们还远吗?
查看>>
Java日志框架-Spring中使用Logback(Spring/Spring MVC)
查看>>
读书笔记--101个shell脚本 之#12--函数
查看>>
TCP/IP之(四)Delay ack 和 Nagle算法
查看>>
linux学习:selinux 禁用后(disabled)Linux系统无法正常启动解决
查看>>
关于tomcat和jetty对比(不喜欢jetty的勿看)
查看>>
grafana使用详解
查看>>