hdu 4920 Matrix multiplication bitset优化常数
Matrix multiplication
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
bobo hates big integers. So you are only asked to find the result modulo 3.
The first line contains n (1≤n≤800). Each of the following n lines contain n integers -- the description of the matrix A. The j-th integer in the i-th line equals Aij. The next n lines describe the matrix B in similar format (0≤Aij,Bij≤109).
Print n lines. Each of them contain n integers -- the matrix A×B in similar format.
0
1
2
0 1
2 3
4 5
6 7
0 1
2 1
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define eps 1e-14
const int N=1e3+,M=1e6+,inf=1e9+;
const ll INF=1e18+,mod=;
int n;
bitset<N>a[N][],b[N][];
int ans(int i,int j)
{
int u=(a[i][]&b[j][]).count(),v=(a[i][]&b[j][]).count();
int x=(a[i][]&b[j][]).count(),y=(b[j][]&a[i][]).count();
return u+v*+x*+y*;
}
int main()
{
while(~scanf("%d",&n))
{
for(int i=;i<n;i++)
for(int j=;j<=;j++)
a[i][j].reset(),b[i][j].reset();
for(int i=; i<n; i++)
for(int j=; j<n; j++)
{
int x;
scanf("%d",&x);
a[i][x%].set(j);
}
for(int i=; i<n; i++)
for(int j=; j<n; j++)
{
int x;
scanf("%d",&x);
b[j][x%].set(i);
}
for(int i=;i<n;i++)
{
for(int j=;j<n;j++)
printf("%d%c",ans(i,j)%,(j!=n-?' ':'\n'));
}
}
return ;
}
hdu 4920 Matrix multiplication bitset优化常数的更多相关文章
- HDU 4920 Matrix multiplication(bitset)
HDU 4920 Matrix multiplication 题目链接 题意:给定两个矩阵,求这两个矩阵相乘mod 3 思路:没什么好的想法,就把0的位置不考虑.结果就过了.然后看了官方题解,上面是用 ...
- HDU 4920 Matrix multiplication(bitset优化)
题目链接 Matrix multiplication 求矩阵A和B相乘的结果. 因为答案只要对3取模,所以我们可以通过一些方法来加速计算. 我们对两个矩阵各开两个bitset,分别存储模3余1和模3余 ...
- hdu 4920 Matrix multiplication(矩阵乘法)2014多培训学校5现场
Matrix multiplication Time ...
- HDU 4920 Matrix multiplication 矩阵相乘。稀疏矩阵
Matrix multiplication Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/ ...
- HDU 4920 Matrix multiplication(矩阵相乘)
各种TEL,233啊.没想到是处理掉0的情况就能够过啊.一直以为会有极端数据.没想到居然是这种啊..在网上看到了一个AC的奇妙的代码,经典的矩阵乘法,仅仅只是把最内层的枚举,移到外面就过了啊...有点 ...
- hdu - 4920 - Matrix multiplication(缓存优化+开挂)
题意:求两个n x n的矩阵相乘后模3的结果,n <= 800. 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4920 -->>呀呀 ...
- HDU 4920 Matrix multiplication (硬件优化)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4920 解题报告:求两个800*800的矩阵的乘法. 参考这篇论文:http://wenku.baidu ...
- 2014多校第五场1010 || HDU 4920 Matrix multiplication(矩阵乘法优化)
题目链接 题意 : 给你两个n*n的矩阵,然后两个相乘得出结果是多少. 思路 :一开始因为知道会超时所以没敢用最普通的方法做,所以一直在想要怎么处理,没想到鹏哥告诉我们后台数据是随机跑的,所以极端数据 ...
- hdu 4920 Matrix multiplication (矩阵计算)
题目链接 题意:给两个矩阵a, b, 计算矩阵a*b的结果对3取余. 分析:直接计算时间复杂度是O(n^3),会超时,但是下面第一个代码勉强可以水过,数据的原因. #include <iostr ...
随机推荐
- react lazyload
思路: DOM加载时,<img> 标签里,添加data-src路径 = src 路径, src路径 = 本地默认图片路径, DOM加载完成后,监听页面可视区域,有data-src时,就将s ...
- LED将为我闪烁:控制发光二极管
一个完整的linux驱动主要由内部处理和与硬件交互两部分组成.其中内部处理主要是指linux驱动的装载.卸载.与设备文件相关的动作处理以及业务逻辑等:与硬件交互主要是指通过iowrite32.io ...
- [整理]Centos6.5 + hadoop2.6.4环境搭建
搭建Hadoop集群环境(3台机器) 1 准备环境 1.1 安装系统,并配置网络使3台机器互联互通,且SSH可直连(无需密码.保存私钥) 1.1.1 安装系统 安装Centos 6.5系统 安装过程略 ...
- 查看SQL语句在SQL Server上的执行时间
set statistics profile onset statistics io onset statistics time ongo--begin <这里写上你的语句...> se ...
- 二十五、JDK1.5新特性---枚举
与上篇文章介绍的相同,本文也是介绍jdk 1.5出现的新特性,本文将介绍枚举的相关用法. 在jdk 1.5 之前.Java可以有两种方式定义新类型:类和接口.对于大部分面向对象来说.这两种方法看起来似 ...
- vue.js 渲染完成回调
vue.js渲染完成后,想触发一些事情,写在哪里呢? 答案是mounted 例子: new Vue({ el:'#demo', data:{ text:'Hello' }, mounted:funct ...
- C# 自动Ping 测试服务器运行状况
通过小程序自动Ping配置文件中的IP地址,间隔时间.IP地址.手机号码通过配置文件获得. 废话不多说,上代码. using Newtonsoft.Json; using Newtonsoft.Jso ...
- 2013ACM/ICPC亚洲区南京站现场赛-HDU4809(树形DP)
为了这个题解第一次写东西..(我只是来膜拜爱看touhou的出题人的).. 首先以为对称性质..我们求出露琪诺的魔法值的期望就可以了..之后乘以3就是答案..(话说她那么笨..能算出来么..⑨⑨⑨⑨⑨ ...
- mssql数据库添加,修改,删除字段
通用式: alter table [表名] add [字段名] 字段属性 default 缺省值 default 是可选参数 增加字段: alter table [表名] add 字段名 smalli ...
- python_函数
一.map 遍历序列,对序列中每个元素进行操作,最终获取新的序列 li = [11,22,33,44] new_list = map(lambda a: a + 100,li) print(new_l ...