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())==' ...
随机推荐
- Android的Observable和iOS的NotificationCenter
使用起来很类似,参看以下网址http://stackoverflow.com/questions/10327200/equivalent-of-ios-nsnotificationcenter-in- ...
- Objective-C 和 C++中指针的格式和.方法 和内存分配
最近在看cocos2d-x,于是打算复习一下C++,在这里简单对比下,留个念想. 先看看oc中指针的用法 @interface ViewController : UIViewController { ...
- Java for LeetCode 050 Pow(x, n)
Implement pow(x, n). 解题思路: 直接使用乘法实现即可,注意下,如果n很大的话,递归次数会太多,因此在n=10和n=-10的地方设置一个检查点,JAVA实现如下: static p ...
- c++流的读写
std::istream input_stream;//这是一个文件流,想把它写入文件 思路是,先将input_stream流读入一个char* buffer; 然后用std::ofstream将bu ...
- 查看MySQL配置文件路径及相关配置
[root@DB ~]# /usr/local/mysql/bin/mysqld --verbose --help |grep -A 1 'Default options' Default optio ...
- barrier()函数
转自:http://blog.chinaunix.net/uid-21961753-id-1810628.html 今天看内核发现disable_preempt这个函数,觉得挺有意思就看了下网上资料, ...
- HTML 调用iscroll.js主要事项
iscroll是一款很不错的滚动控件(js),但是在调用的时候,需要注意一些事项: 1.iscroll支持水平和垂直滚动,那么在调用的时候,一定注意滚动div必须大于父div,也就是说,父div的宽度 ...
- UVa 11524:In-Circle(解析几何)
Problem EIn-CircleInput: Standard Input Output: Standard Output In-circle of a triangle is the circl ...
- J2EE面试题集锦(附答案)
转自:http://blog.sina.com.cn/s/blog_4e8be0590100fbb8.html J2EE面试题集锦(附答案)一.基础问答 1.下面哪些类可以被继承? java.lang ...
- HDU 4348 To the moon 可持久化线段树
To the moon Problem Description BackgroundTo The Moon is a independent game released in November 201 ...