您的位置:首页 > 其它

POJ 3318 Matrix Multiplication 输入外挂z

2015-10-31 18:43 281 查看
Matrix Multiplication

Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 17587 Accepted: 3799
Description

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
[Submit]   [Go Back]   [Status]  
[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*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: