Acdream 1213 matrix multiplication (matrix multiplication)

Source: Internet
Author: User
Tags cmath

Title Link: http://acdream.info/problem?pid=1213

There are many mathematical knowledge involved, including the matrix transpose, matrix multiplication, correlation matrix ....

The first is directly in accordance with the concept of the results of the MLE, the MLE code is as follows

#include <cstdio> #include <iostream> #include <sstream> #include <cstdlib> #include < cstring> #include <string> #include <climits> #include <cmath> #include <algorithm> #include <queue> #include <vector> #include <stack> #include <set> #include <map>using namespace    Std;int n,m;int A[10005][5],v[10005][10005],v1[10005][10005];int Main () {int i,j;        while (~SCANF ("%d%d", &n,&m)) {memset (v,0,sizeof (v));        memset (v1,0,sizeof (v1));        for (i=0;i<m;i++) for (j=0;j<2;j++) scanf ("%d", &a[i][j]);        for (i=0;i<m;i++) v[a[i][0]-1][a[i][1]-1]=v[a[i][1]-1][a[i][0]-1]=1;        for (i=0;i<n;i++) for (j=0;j<m;j++) v1[j][i]=v[i][j];        int sum=0,b=0,k=m;                while (k--) {for (i=0;i<n;i++) {int c=0; for (j=0;j<m;j++) {SUM+=V[B][C++]*V1[j]                [i];        }} b++;    } printf ("%d\n", sum); } return 0;}

On the Internet to see other people's solution to get ideas, the following is the AC code

#include <cstdio> #include <iostream> #include <sstream> #include <cstdlib> #include < cstring> #include <string> #include <climits> #include <cmath> #include <algorithm> #include <queue> #include <vector> #include <stack> #include <set> #include <map>using namespace Std;int n,m;int A[100005];int Main () {    int i,j;    while (~SCANF ("%d%d", &n,&m))    {        int u,v;        memset (a,0,sizeof (v));        for (I=1; i<=m; i++)        {            scanf ("%d%d", &u,&v);            a[u]++;            a[v]++;        }        Long long sum=0;        for (I=1; i<=n; i++)            sum+=a[i]*a[i];        printf ("%lld\n", sum);    }    return 0;}



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Acdream 1213 matrix multiplication (matrix multiplication)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.