HUST 1615 Matrix
来源:互联网 发布:商超软件 编辑:程序博客网 时间:2024/05/16 06:26
To efficient calculate the multiplication of a sparse matrix is very useful in industrial filed.
Let’s consider this problem:
A is an N*N matrix which only contains 0 or 1. And we want to know the result of A*AT.
Formally, we define B = A*AT, A(i,j) is equal to 1 or 0, and we know the number of 1 in matrix A is M
And your task is to calculate B.
Input
The input contains several test cases. The first line of input contains a integer C indicating the number of the cases.
For each test case, the first line contains two integer N and M.
and each of next M lines contains two integer X and Y, which means A(x,y) is 1.
N <= 100,000 M <= 1000.C <= 10
Output
For each test case, it should have a integer W indicating how many element in Matrix B isn’t zero in one line.
题意:求B中非0的个数
#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <iostream>#include <vector>#include <set>#include <map>using namespace std;struct node{ int x,y; bool operator < (const node &a)const { if(a.x!=x) return a.x>x; return a.y>y; }}pi[1007];map<node,int> q;int main(){ int t; cin>>t; while(t--) { int n,m; cin>>n>>m; q.clear(); for(int i=0;i<m;i++) cin>>pi[i].x>>pi[i].y; int cnt=0; for(int i=0;i<m;i++) { for(int j=0;j<m;j++) { node tmp; tmp.x=pi[i].x,tmp.y=pi[j].x; if(pi[i].y==pi[j].y&&q[tmp]==0) { q[tmp]=1; cnt++; } } } cout<<cnt<<endl; }}
- HUST 1615 Matrix
- HUST 1615 Matrix
- hust校赛 1615 Matrix 矩阵和其逆矩阵的乘积中不为0的元素个数
- HUST
- HUST
- HUST
- HUST
- HUST 1328
- HUST-1010
- HUST 1408
- hust 1602
- HUST 1525
- hust 1010
- HUST 1422
- HUST 1563
- hust 1592
- HUST 1017
- HUST 1017
- Spring之IOC容器
- IO
- Spring学习笔记(一)Spring 概述
- Python中的编码问题
- eclipse安装插件 windowbuilder --- 可视化swing设计界面
- HUST 1615 Matrix
- 网络判断逻辑及三种方式(工具类)
- 如何写一个单纯的OpenGL2.0程序
- 使用StarUML画类图
- case class
- grep指令详解
- SpringMVC中Controller的@ResponseBody注解的分析
- Java线程学习(一)线程的创建和执行
- 零基础搭建Hadoop大数据处理-初识