POJ 3318 - Matrix Multiplication 第一次用随机化解决问题...
随机化还是很厉害的...印象最深的是以前手写快排~~一般加个随机化会使耗时不受输入数据的..时间更加稳定
这个题是人品题了...开始交了好多遍都过不了..多交几次终于过了...
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 第一次用随机化解决问题...的更多相关文章
- 数学(矩阵乘法,随机化算法):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: ...
- poj 3318 Matrix Multiplication 随机化算法
方法1:暴力法 矩阵乘法+优化可以卡时间过的. 方法2:随机化 随机构造向量x[1..n],则有xAB=xC;这样可以将小运算至O(n^2). 代码如下: #include<iostream&g ...
- [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
http://poj.org/problem?id=3318 矩阵A*矩阵B是否等于矩阵C #include <cstdio> #include <cstring> #incl ...
- POJ 3318 Matrix Multiplication(随机算法)
题目链接 随机算法使劲水...srand((unsigned)time(0))比srand(NULL)靠谱很多,可能是更加随机. #include <cstdio> #include &l ...
- POJ 3318 Matrix Multiplication(矩阵乘法)
题目链接 题意 : 给你三个n维矩阵,让你判断A*B是否等于C. 思路 :优化将二维转化成一维的.随机生成一个一维向量d,使得A*(B*d)=C*d,多次生成多次测试即可使错误概率大大减小. #inc ...
- PKU 3318 Matrix Multiplication(随机化算法||状态压缩)
题目大意:原题链接 给定三个n*n的矩阵A,B,C,验证A*B=C是否成立. 所有解法中因为只测试一组数据,因此没有使用memset清零 Hint中给的傻乎乎的TLE版本: #include<c ...
- PKU 3318 Matrix Multiplication(神奇的输入)
#include<cstdio> using namespace std; ][]; ][],C[][]; int Read() { ; ; while((ch=getchar())==' ...
随机推荐
- Python中:self和__init__的含义 + 为何要有self和__init__
Python中:self和__init__的含义 + 为何要有self和__init__ 背景 回复: 我写的一些Python教程,需要的可以看看 中SongShouJiong的提问: Python中 ...
- get方式中文乱码问题
<a target="_blank" href="ftpFileAction!downloadFile.action?filename=测试.xml"&g ...
- 又一道简单题&&Ladygod(两道思维水题)
Ladygod Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submit S ...
- Codeforces Round #156 (Div. 2)---A. Greg's Workout
Greg's Workout time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- C#版QQTea加密
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Wind ...
- POJ 3678 Katu Puzzle(2 - SAT) - from lanshui_Yang
Description Katu Puzzle is presented as a directed graph G(V, E) with each edge e(a, b) labeled by a ...
- JQuery(一)——初步总结
JQuery其实早就看过相关的视频了,但是由于当时查的资料太少,理解的不够深刻,所以没有进行总结,这次回过头来又学习了,心里感觉理解了很多,因为BS的其它知识基本学习完了,而且有了一定程度的理解.相互 ...
- About
about: Thanks to NetEase company, the people contribute to NetEase online course, Stephen Prata(< ...
- Qt使用快捷键
在说快捷键之前先来说一个QtCreator调试的过程中经常发生的一个问题. 问题描述: 用QtCreator建立了一个纯C++的项目,但是在F5调试时,竟然提示ptrace不允许的操作,修改工程配置为 ...
- jQuery 源码分析和使用心得 - 关于源码
说到jQuery, 大家可能直觉的认为jQuery的源码应该就是一个jquery.xx.js这样的一个文件. 但是看到真正的源码的时候, 整个人都思密达了.jQuery的源码做的事远比你想象的多, 为 ...