POJ 3318 Matrix Multiplication(随机算法)
随机算法使劲水...srand((unsigned)time(0))比srand(NULL)靠谱很多,可能是更加随机。
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <map>
#include <ctime>
#include <cmath>
using namespace std;
#define LL __int64
int a[][],b[][],c[][];
int main()
{
int i,j,k,flag,n;
srand((unsigned)time());
while(scanf("%d",&n)!=EOF)
{
for(i = ; i <= n; i ++)
{
for(j = ; j <= n; j ++)
scanf("%d",&a[i][j]);
}
for(i = ; i <= n; i ++)
{
for(j = ; j <= n; j ++)
scanf("%d",&b[i][j]);
}
for(i = ; i <= n; i ++)
{
for(j = ; j <= n; j ++)
scanf("%d",&c[i][j]);
}
flag = ;
for(i = ; i <= &&flag; i ++)
{
LL temp = ;
int x,y;
x = rand()%n + ;
y = rand()%n + ;
for(k = ; k <= n; k ++)
{
temp += a[x][k]*b[k][y];
}
if(temp != c[x][y])
flag = ;
}
if(flag)
printf("YES\n");
else
printf("NO\n");
}
return ;
}
POJ 3318 Matrix Multiplication(随机算法)的更多相关文章
- poj 3318 Matrix Multiplication 随机化算法
方法1:暴力法 矩阵乘法+优化可以卡时间过的. 方法2:随机化 随机构造向量x[1..n],则有xAB=xC;这样可以将小运算至O(n^2). 代码如下: #include<iostream&g ...
- 数学(矩阵乘法,随机化算法):POJ 3318 Matrix Multiplication
Matrix Multiplication Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 17783 Accepted: ...
- Poj 3318 Matrix Multiplication( 矩阵压缩)
Matrix Multiplication Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 18928 Accepted: ...
- PKU 3318 Matrix Multiplication(随机化算法||状态压缩)
题目大意:原题链接 给定三个n*n的矩阵A,B,C,验证A*B=C是否成立. 所有解法中因为只测试一组数据,因此没有使用memset清零 Hint中给的傻乎乎的TLE版本: #include<c ...
- poj 3318 Matrix Multiplication
http://poj.org/problem?id=3318 矩阵A*矩阵B是否等于矩阵C #include <cstdio> #include <cstring> #incl ...
- [poj 3318] Matrix Multiplication (随机化+矩阵)
Description You are given three n × n matrices A, B and C. Does the equation A × B = C hold true? In ...
- POJ 3318 Matrix Multiplication(矩阵乘法)
题目链接 题意 : 给你三个n维矩阵,让你判断A*B是否等于C. 思路 :优化将二维转化成一维的.随机生成一个一维向量d,使得A*(B*d)=C*d,多次生成多次测试即可使错误概率大大减小. #inc ...
- POJ 3318 - Matrix Multiplication 第一次用随机化解决问题...
随机化还是很厉害的...印象最深的是以前手写快排~~一般加个随机化会使耗时不受输入数据的..时间更加稳定 这个题是人品题了...开始交了好多遍都过不了..多交几次终于过了... Program: #i ...
- PKU 3318 Matrix Multiplication(神奇的输入)
#include<cstdio> using namespace std; ][]; ][],C[][]; int Read() { ; ; while((ch=getchar())==' ...
随机推荐
- 搭建自己的SIP服务器:开源sip服务器opensips的搭建及终端TwInkle的使用
搭建自己的SIP服务器:开源sip服务器opensips的搭建及终端TwInkle的使用 分类: linux编译相关2013-01-05 21:38 17983人阅读 评论(24) 收藏 举报 先下载 ...
- Git SSH Key 生成步骤
it是分布式的代码管理工具,远程的代码管理是基于ssh的,所以要使用远程的git则需要ssh的配置. github的ssh配置如下: 一 . 设置git的user name和email: $ git ...
- 【Python】 Django 怎么实现 联合主键?
unique_together¶ Options.unique_together¶ Sets of field names that, taken together, must be unique: ...
- svn 设置
\Release *\Debug *\bin *\Bin *\obj *\_ReSharper* *\.hg *.ReSharper *.resharper *\Generated_Code *\VB ...
- codeigniter 视图
2014年7月7日 15:23:05 ci的视图功能很棒, 比如一个网页有四个部分组成,对应4个文件:header.php, sider.php, maincontent.php, footer .p ...
- NEXTDAY
#include <stdio.h> #include <stdlib.h> #include <string.h> #include "com_time ...
- php 用面向对象的方法对数据库增删改查
主页面 <body> <h1>主页面</h1> <table width="100%" border="1" cell ...
- Feed系统架构资料收集
完全用nosql轻松打造千万级数据量的微博系统 微博feed系统的push和pull模式和时间分区拉模式架构探讨 关于如何构建一个微博型广播 关于如何构建一个微博型广播2 用 mongodb 储存多态 ...
- 通过扩展让ASP.NET Web API支持W3C的CORS规范(转载)
转载地址:http://www.cnblogs.com/artech/p/cors-4-asp-net-web-api-04.html CORS(Cross-Origin Resource Shari ...
- ER-Studio的五种关系说明
1. identifying relationship: 1对多. 父实体的主键是子实体的外键(FK1),且FK1是主键. 2. no identifying, mandatory relations ...