poj 3213 PM3

题目链接:http://poj.org/problem?id=3213

解题思路:直接模拟矩阵相乘

  1 /**************************************************************************
  2 user_id: SCNU20102200088
  3 problem_id: poj 3213
  4 problem_name: PM3
  5 **************************************************************************/
  6 
  7 #include <algorithm>
  8 #include <iostream>
  9 #include <iterator>
 10 #include <iomanip>
 11 #include <sstream>
 12 #include <fstream>
 13 #include <cstring>
 14 #include <cstdlib>
 15 #include <climits>
 16 #include <bitset>
 17 #include <string>
 18 #include <vector>
 19 #include <cstdio>
 20 #include <cctype>
 21 #include <ctime>
 22 #include <cmath>
 23 #include <queue>
 24 #include <stack>
 25 #include <list>
 26 #include <set>
 27 #include <map>
 28 using namespace std;
 29 
 30 //线段树
 31 #define lson l,m,rt<<1
 32 #define rson m+1,r,rt<<1|1
 33 
 34 //手工扩展栈
 35 #pragma comment(linker,"/STACK:102400000,102400000")
 36 
 37 const double EPS=1e-9;
 38 const double PI=acos(-1.0);
 39 const double E=2.7182818284590452353602874713526;  //自然对数底数
 40 const double R=0.5772156649015328606065120900824;  //欧拉常数:(1+1/2+...+1/n)-ln(n)
 41 
 42 const int x4[]={-1,0,1,0};
 43 const int y4[]={0,1,0,-1};
 44 const int x8[]={-1,-1,0,1,1,1,0,-1};
 45 const int y8[]={0,1,1,1,0,-1,-1,-1};
 46 
 47 typedef long long LL;
 48 
 49 typedef int T;
 50 T max(T a,T b){ return a>b? a:b; }
 51 T min(T a,T b){ return a<b? a:b; }
 52 T gcd(T a,T b){ return b==0? a:gcd(b,a%b); }
 53 T lcm(T a,T b){ return a/gcd(a,b)*b; }
 54 
 55 ///////////////////////////////////////////////////////////////////////////
 56 //Add Code:
 57 int N,P,M,A[1005][1005],B[1005][1005],C[1005][1005];
 58 ///////////////////////////////////////////////////////////////////////////
 59 
 60 int main(){
 61     std::ios::sync_with_stdio(false);
 62     //freopen("in.txt","r",stdin);
 63     //freopen("out.txt","w",stdout);
 64     ///////////////////////////////////////////////////////////////////////
 65     //Add Code:
 66     int i,j,k;
 67     while(scanf("%d%d%d",&N,&P,&M)!=EOF){
 68         for(i=1;i<=N;i++){
 69             for(j=1;j<=P;j++) scanf("%d",&A[i][j]);
 70         }
 71         for(i=1;i<=P;i++){
 72             for(j=1;j<=M;j++) scanf("%d",&B[i][j]);
 73         }
 74         for(i=1;i<=N;i++){
 75             for(j=1;j<=M;j++) scanf("%d",&C[i][j]);
 76         }
 77         bool flag=1;
 78         int row=0,col=0,ans=0;
 79         for(i=1;i<=N;i++){
 80             for(j=1;j<=M;j++){
 81                 int temp=0;
 82                 for(k=1;k<=P;k++) temp+=A[i][k]*B[k][j];
 83                 if(temp!=C[i][j]){
 84                     flag=0;
 85                     row=i;
 86                     col=j;
 87                     ans=temp;
 88                     goto out;
 89                 }
 90             }
 91         }
 92         out:;
 93         if(flag) printf("Yes\n");
 94         else{
 95             printf("No\n");
 96             printf("%d %d\n",row,col);
 97             printf("%d\n",ans);
 98         }
 99     }
100     ///////////////////////////////////////////////////////////////////////
101     return 0;
102 }
103 
104 /**************************************************************************
105 Testcase:
106 Input:
107 2 3 2
108 1 2 -1
109 3 -1 0
110 -1 0
111 0 2
112 1 3
113 -2 -1
114 -3 -2
115 Output:
116 No
117 1 2
118 1
119 **************************************************************************/

posted on 2013-10-11 15:41  SCNU20102200088  阅读(377)  评论(0编辑  收藏  举报

导航