随机化还是很厉害的...印象最深的是以前手写快排~~一般加个随机化会使耗时不受输入数据的..时间更加稳定

这个题是人品题了...开始交了好多遍都过不了..多交几次终于过了...

Program:

#include<iostream>
#include<stack>
#include<queue>
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<time.h>
#include<cmath>
#define ll long long
#define oo 1000000007
#define MAXN 505
using namespace std;
int n,M[3][MAXN][MAXN];
bool judge()
{
int t,i,j,x,y,p,d;
for (t=1;t<=60000;t++)
{
y=rand()%n;
x=rand()%n;
d=0;
for (p=0;p<n;p++)
d+=M[0][y][p]*M[1][p][x];
if (d!=M[2][y][x]) return false;
}
return true;
}
int main()
{
int i,j,x;
scanf("%d",&n);
for (x=0;x<3;x++)
for (i=0;i<n;i++)
for (j=0;j<n;j++)
scanf("%d",&M[x][i][j]);
srand((unsigned)time(NULL));
if (judge()) printf("YES\n");
else printf("NO\n");
return 0;
}

POJ 3318 - Matrix Multiplication 第一次用随机化解决问题...的更多相关文章

  1. 数学(矩阵乘法,随机化算法):POJ 3318 Matrix Multiplication

    Matrix Multiplication Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17783   Accepted: ...

  2. Poj 3318 Matrix Multiplication( 矩阵压缩)

    Matrix Multiplication Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 18928   Accepted: ...

  3. poj 3318 Matrix Multiplication 随机化算法

    方法1:暴力法 矩阵乘法+优化可以卡时间过的. 方法2:随机化 随机构造向量x[1..n],则有xAB=xC;这样可以将小运算至O(n^2). 代码如下: #include<iostream&g ...

  4. [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 ...

  5. poj 3318 Matrix Multiplication

    http://poj.org/problem?id=3318 矩阵A*矩阵B是否等于矩阵C #include <cstdio> #include <cstring> #incl ...

  6. POJ 3318 Matrix Multiplication(随机算法)

    题目链接 随机算法使劲水...srand((unsigned)time(0))比srand(NULL)靠谱很多,可能是更加随机. #include <cstdio> #include &l ...

  7. POJ 3318 Matrix Multiplication(矩阵乘法)

    题目链接 题意 : 给你三个n维矩阵,让你判断A*B是否等于C. 思路 :优化将二维转化成一维的.随机生成一个一维向量d,使得A*(B*d)=C*d,多次生成多次测试即可使错误概率大大减小. #inc ...

  8. PKU 3318 Matrix Multiplication(随机化算法||状态压缩)

    题目大意:原题链接 给定三个n*n的矩阵A,B,C,验证A*B=C是否成立. 所有解法中因为只测试一组数据,因此没有使用memset清零 Hint中给的傻乎乎的TLE版本: #include<c ...

  9. PKU 3318 Matrix Multiplication(神奇的输入)

    #include<cstdio> using namespace std; ][]; ][],C[][]; int Read() { ; ; while((ch=getchar())==' ...

随机推荐

  1. android重要的对象

    Context----------------访问全局信息的api Activity Window Intent/Bundle ImageView----------onclick View----- ...

  2. javascript事件设计模式

    JavaScript事件设计模式 http://plkong.iteye.com/blog/213543 http://www.docin.com/p-696665922.html

  3. 在IE浏览器中iframe跨域访问cookie/session丢失的解决办法

    单点登录需要在需要进入的子系统B中添加一个类,用于接收A系统传过来的参数: @Action(value = "outerLogin", results = { @Result(na ...

  4. 28 个 Unix/Linux 的命令行神器

    28 个 Unix/Linux 的命令行神器   下面是Kristóf Kovács收集的28个Unix/Linux下的28个命令行下的工具(原文链接),有一些是大家熟悉的,有一些是非常有用的,有一些 ...

  5. diff函数(matlab)

    diff函数式用于求导数和差分的.无论是求导数还是差分,其原理是一样的. 这里简单介绍下其用法: 前后相邻元素之差 上下相邻行之差. 与diff(A,1,1)类似. 第三个参数为2时,则变为列差分运算 ...

  6. PHP单例模式编写

    今天来点基础的设计模式: 如何利用单例模式实现一个数据库中间层 class Db{ static private $_instance; //当前数据库连接实例 static public funct ...

  7. 【HDU】4092 Nice boat(多校第四场1006) ——线段树 懒惰标记

    Nice boat Time Limit: 30000/15000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) To ...

  8. mac 上配置sublime text3插件

    1.安装MAC 版 sublime text 3 安装插件管理器 打开Sublime,按下Control + `(Mac)或者Ctrl + `(Windows),然后粘贴上下面的代码: import ...

  9. mongodb 学习笔记 04 -- 游标、索引

    游标 var cursor = db.collectionName.find() 创建游标 cursor.hasNext() 是否有下一个元素 cursor.next() 取出下一个元素 比如 whi ...

  10. BPM7.5.1升级细节,万事开头难

    背景:Linux5.9,BPM 7.5.0集群环境,内置WAS ND7.0.0.17 详情见上图 故障现象:升级BPM 7.5.1集群环境 1,按照 IBM 信息中心步骤,升级BPM需下载相应补丁 包 ...