COJ 1068: Count the Number of Cycles(向量点积)
2014-07-14 22:04
337 查看
CounttheNumberofCycles
TimeLimit:1SecMemoryLimit:
128MB
Description
Ininformationtheory,alow-densityparity-check(LDPC)codeisalinearerrorcorrectingcode,amethodoftransmittingamessageoveranoisytransmissionchannel,andisconstructedusingasparsebipartitegraph.LDPCcodesarecapacity-approachingcodes,whichmeansthatpracticalconstructionsexistthatallowthenoisethresholdtobesetveryclose(orevenarbitrarilycloseontheBEC)tothetheoreticalmaximum(theShannonlimit)
forasymmetricmemory-lesschannel.
LDPCcodesaredefinedbyasparseparity-checkmatrix.Thisparity-checkmatrixisoftenrandomlygeneratedandtheelementsinitare0or1.IfwewantuseLDPCcodes,weshould
maketheparity-checkmatrixhavenocycles.Whenfourverticesoftherectangleinthematrixare1,wesaythatthematrixhasonecycle.Nowwewanttoknowhowmanycyclesareinthematrix.
Foragivenmatrix,youaretocountthenumberofcyclesinthematrix.
Input
Thereareseveraltestcases,eachtestcasestartswithalinecontainingtwopositiveintegersMandN.MandNisthesizeofthematrix(1<=M<=100,1<=N<=100).Nextfollowamatrixwhichcontainsonlynumber0and1.Theinputwillfinishwiththeendoffile.
Output
.Foreachthecase,yourprogramwilloutputthenumberofcyclesinthegivenmatrixonseparateline.SampleInput
13 111 23 101 011 33 101 011 111
SampleOutput
0 0 2
此题计算的是正矩形的数量,不包含斜着的矩形的数量,采用的方法为向量的点乘积。
对于每一行的N个元素可以看做是一个向量,一共有M个向量。
对于每两个向量,如果两个向量的点乘积为sum,则这两行可以构成C(sum,2)个矩形,把所有的相加即可。
代码如下:
#include<iostream>
#include<stdio.h>
usingnamespacestd;
constintmaxn=100+5;
inta[maxn][maxn];
intmain()
{
intm,n,i,j,k,s;
while(scanf("%d%d",&m,&n)!=EOF)
{
intcot=0;
for(i=0;i<m;i++)
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
s=m-1;
for(i=0;i<s;i++)
{
intsum=0;
for(j=i+1;j<m;j++)
{
for(k=0;k<n;k++)
{sum+=a[i][k]*a[j][k];}
cot+=sum*(sum-1)/2;
sum=0;
}
}
printf("%d\n",cot);
}
return0;
}
相关文章推荐
- HLG 1253 Count the Number of Cycles【ldpc环】
- Count the number of 1(MIT hackmem)
- OpenCV count the number of connected camera 检测连接的摄像头的数量
- 在排序数组中的出现次数 Count the number of occurrences in a sorted array
- *Count the number of possible triangles
- count the number of 1 in a decimal integer
- Count the number of occurrences in a sorted array
- Regex 101 Exercise I9 - Count the number of matches
- [geeksforgeeks] Count the number of occurrences in a sorted array
- Count the number of bits that are on in an unsigned integer(计算一个无符整数中1Bit的个数)-- (1)
- How to count the number of threads in a process on Linux
- count the number of objects--物体计数
- Count the number of possible triangles
- Count the number of alphabets, spaces, digits and other characters in one line character
- python int to binary and count the number of 1
- 三角形的数目 Count the number of possible triangles
- count the number of "1" in the binary figure
- quick count the number of the rows in a big table
- Q9.11 count the number of ways of parenthesizing the expression
- count the number of 2s