题目链接

随机算法使劲水...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(随机算法)的更多相关文章

  1. poj 3318 Matrix Multiplication 随机化算法

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

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

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

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

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

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

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

  5. poj 3318 Matrix Multiplication

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

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

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

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

  8. POJ 3318 - Matrix Multiplication 第一次用随机化解决问题...

    随机化还是很厉害的...印象最深的是以前手写快排~~一般加个随机化会使耗时不受输入数据的..时间更加稳定 这个题是人品题了...开始交了好多遍都过不了..多交几次终于过了... Program: #i ...

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

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

随机推荐

  1. [转]Ubuntu 系统 Update-rc.d 命令

    本文转自:http://wangyan.org/blog/ubuntu-update-rc-d.html 以防止原博客挂掉,特此做了备份. Ubuntu或者Debian系统中update-rc.d命令 ...

  2. windows下的C/C++精确计时

    由于我要测试线性筛法的速度,用上了C/C++精确计时.此时传统的clock()方法不够用了,我们需要另一种测量的办法,即CPUTicks/CPUFreq.如何实现呢? #include <win ...

  3. Sphinx 增量索引更新

    是基于PHP API调用,而不是基于sphinxSE.现在看来sphinxSE比API调用更简单的多,因为之前没有想过sphinxSE,现在先把API的弄明白.涉及到的:sphinx 数据源的设置,简 ...

  4. Serialize and Deserialize Binary Tree

    Design an algorithm and write code to serialize and deserialize a binary tree. Writing the tree to a ...

  5. Linux匿名管道与命名管道

    http://blog.chinaunix.net/uid-26000296-id-3408970.html /* * \File * main.c * \Descript * father-proc ...

  6. Java for LeetCode 052 N-Queens II

    Follow up for N-Queens problem. Now, instead outputting board configurations, return the total numbe ...

  7. tomcat启动,输出system.out.println()

    tomcat6.0在使用System.out.println("aa")的时候,用cmd启动startup.bat,弹出的那个cmd窗口看到 还可以看logs/catalina.o ...

  8. php 指针遍历、预定义数组和常用函数

    <?php /*//定义 $attr = array(1,2,3); $attr[] = 1; $attr = array("one"=>"hello&quo ...

  9. 精灵动画Animation对话框组成Idle动画的各精灵

    精灵动画Animation对话框组成Idle动画的各精灵 1.3  精灵动画 场景中已经添加了精灵,现在是时候让让它动起来了.读者也许已经从精灵图集中,各精灵的命名中看出来了,这个精灵一共有两种动画状 ...

  10. 01背包 URAL 1073 Square Country

    题目传送门 /* 题意:问n最少能是几个数的平方和 01背包:j*j的土地买不买的问题 详细解释:http://www.cnblogs.com/vongang/archive/2011/10/07/2 ...