POJ 3318 Matrix Multiplication 输入外挂z
2015-10-31 18:43
281 查看
Matrix Multiplication
You are given three n × n matrices A, B and C. Does the equation A × B = C hold true? Input The first line of input contains a positive integer n (n ≤ 500) followed by the the three matrices A, B and C respectively. Each matrix's description is a block of n × n integers. It guarantees that the elements of A and B are less than 100 in absolute value and elements of C are less than 10,000,000 in absolute value. Output Output "YES" if the equation holds true, otherwise "NO". Sample Input 2 1 0 2 3 5 1 0 8 5 1 10 26 Sample Output YES Hint Multiple inputs will be tested. So O(n3) algorithm will get TLE. Source POJ Monthly--2007.08.05, qzc |
[Discuss]
涨姿势哦
输入外挂强行n3水过
ACcode:
#pragma warning(disable:4786)//使命名长度不受限制
#pragma comment(linker, "/STACK:102400000,102400000")//手工开栈
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <stack>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d%d",&x,&y)
#define rds(x) scanf("%s",x)
#define rdc(x) scanf("%c",&x)
#define ll long long int
#define maxn 505
#define mod 1000000007
#define INF 0x3f3f3f3f //int 最大值
#define FOR(i,f_start,f_end) for(int i=f_start;i<=f_end;++i)
#define MT(x,i) memset(x,i,sizeof(x))
#define PI acos(-1.0)
#define E exp(1)
using namespace std;
int a[maxn][maxn],b[maxn][maxn],c[maxn][maxn];
inline int Scan(){
int d=0;
char c,t=0;
while((c=getchar())==' '||c=='\n');
if(c=='-')t=1;
else d=c-'0';
while((c=getchar())>='0'&&c<='9')
d=d*10+c-'0';
if(t)return -d;
else return d;
}
int main(){
int n,t;n=Scan();
FOR(i,1,n)FOR(j,1,n)a[i][j]=Scan();
FOR(i,1,n)FOR(j,1,n)b[i][j]=Scan();
FOR(i,1,n)FOR(j,1,n)c[i][j]=Scan();
FOR(i,1,n)FOR(j,1,n){
t=0;
FOR(k,1,n)t+=a[i][k]*b[k][j];
if(t!=c[i][j]){puts("NO\n");return 0;}
}
puts("YES\n");
return 0;
}
/*
2 1 0 2 3 5 1 0 8 5 1 10 26*/
相关文章推荐
- UML第四集
- 【LEETCODE】226-Invert Binary Tree
- 行为型模式之四——中介者模式
- CSS 使用小结
- 《软件需求工程》阅读笔记之三
- Android——AS VS Eclipse
- android:launchMode、Task、Stack
- Android——AS VS Eclipse
- 我的菜鸟路,第一次在ubuntu 13.10系统上运行c++程序
- Restore Nexus 5 to Stock and Flash Factory Images
- Dynamics CRM 2011 JScript
- 如何在Dynamics CRM 2011 的窗体表单上加载报表
- 随Android程序发布SQLite数据库
- .Net程序员面试所需要的一些技术准备
- POJ3126 Prime Path【数论】【BFS】
- 面向对象的4要素:抽象,封装,继承,多态
- CodeForces 337C 找规律 ,等比数列求和
- Python 创建XML
- weka –Apriori算法 关联规则挖掘实验
- jquery技巧总结