题目链接

随机算法使劲水...srand((unsigned)time(0))比srand(NULL)靠谱很多,可能是更加随机。

  1. #include <cstdio>
  2. #include <cstdlib>
  3. #include <cstring>
  4. #include <map>
  5. #include <ctime>
  6. #include <cmath>
  7. using namespace std;
  8. #define LL __int64
  9. int a[][],b[][],c[][];
  10. int main()
  11. {
  12. int i,j,k,flag,n;
  13. srand((unsigned)time());
  14. while(scanf("%d",&n)!=EOF)
  15. {
  16. for(i = ; i <= n; i ++)
  17. {
  18. for(j = ; j <= n; j ++)
  19. scanf("%d",&a[i][j]);
  20. }
  21. for(i = ; i <= n; i ++)
  22. {
  23. for(j = ; j <= n; j ++)
  24. scanf("%d",&b[i][j]);
  25. }
  26. for(i = ; i <= n; i ++)
  27. {
  28. for(j = ; j <= n; j ++)
  29. scanf("%d",&c[i][j]);
  30. }
  31. flag = ;
  32. for(i = ; i <= &&flag; i ++)
  33. {
  34. LL temp = ;
  35. int x,y;
  36. x = rand()%n + ;
  37. y = rand()%n + ;
  38. for(k = ; k <= n; k ++)
  39. {
  40. temp += a[x][k]*b[k][y];
  41. }
  42. if(temp != c[x][y])
  43. flag = ;
  44. }
  45. if(flag)
  46. printf("YES\n");
  47. else
  48. printf("NO\n");
  49. }
  50. return ;
  51. }

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. Android的Observable和iOS的NotificationCenter

    使用起来很类似,参看以下网址http://stackoverflow.com/questions/10327200/equivalent-of-ios-nsnotificationcenter-in- ...

  2. Objective-C 和 C++中指针的格式和.方法 和内存分配

    最近在看cocos2d-x,于是打算复习一下C++,在这里简单对比下,留个念想. 先看看oc中指针的用法 @interface ViewController : UIViewController { ...

  3. Java for LeetCode 050 Pow(x, n)

    Implement pow(x, n). 解题思路: 直接使用乘法实现即可,注意下,如果n很大的话,递归次数会太多,因此在n=10和n=-10的地方设置一个检查点,JAVA实现如下: static p ...

  4. c++流的读写

    std::istream input_stream;//这是一个文件流,想把它写入文件 思路是,先将input_stream流读入一个char* buffer; 然后用std::ofstream将bu ...

  5. 查看MySQL配置文件路径及相关配置

    [root@DB ~]# /usr/local/mysql/bin/mysqld --verbose --help |grep -A 1 'Default options' Default optio ...

  6. barrier()函数

    转自:http://blog.chinaunix.net/uid-21961753-id-1810628.html 今天看内核发现disable_preempt这个函数,觉得挺有意思就看了下网上资料, ...

  7. HTML 调用iscroll.js主要事项

    iscroll是一款很不错的滚动控件(js),但是在调用的时候,需要注意一些事项: 1.iscroll支持水平和垂直滚动,那么在调用的时候,一定注意滚动div必须大于父div,也就是说,父div的宽度 ...

  8. UVa 11524:In-Circle(解析几何)

    Problem EIn-CircleInput: Standard Input Output: Standard Output In-circle of a triangle is the circl ...

  9. J2EE面试题集锦(附答案)

    转自:http://blog.sina.com.cn/s/blog_4e8be0590100fbb8.html J2EE面试题集锦(附答案)一.基础问答 1.下面哪些类可以被继承? java.lang ...

  10. HDU 4348 To the moon 可持久化线段树

    To the moon Problem Description BackgroundTo The Moon is a independent game released in November 201 ...