merkator

Untitled

Oct 6th, 2011
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.60 KB | None | 0 0
  1. #define FN "matrix"
  2.  
  3. #include<cstdio>
  4. #include<cctype>
  5. #include<iostream>
  6. #include<fstream>
  7. #include<functional>
  8. #include<utility>
  9. #include<vector>
  10. #include<stack>
  11. #include<map>
  12. #include<queue>
  13. #include<deque>
  14. #include<cstdlib>
  15. #include<cmath>
  16. #include<algorithm>
  17. #include<set>
  18. #include<complex>
  19. #include<cstring>
  20. #include<string>
  21. #include<cassert>
  22. #include<iomanip>
  23.  
  24.                
  25. using namespace std;
  26.  
  27. typedef long long LL;
  28.  
  29. #define pb push_back
  30. #define mp make_pair
  31. #define fi first
  32. #define se second
  33. #define all(n) (n).begin(), (n).end()
  34. #define EPS 1e-9
  35. #define INF 1e9
  36. #define forn(i, n) for(int (i) = 0; (i) < (n); ++(i))
  37. #define forab(i, a, b) for(int (i) = a; (i) <= (b); ++(i))
  38. #define forba(i, b, a) for(int (i) = b; (i) >= (a); --(i))
  39. #define forit(i, v) for(__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++i)
  40.  
  41. vector <vector <double> > a,b;
  42.  
  43. int main(){
  44. #ifdef FN
  45.     freopen(FN".in", "r", stdin);
  46.     freopen(FN".out", "w", stdout);
  47. #endif
  48.     int n;
  49.     int m;
  50.     scanf("%d%d", &n, &m);
  51.     a.resize(n);
  52.     forn(i, n){
  53.         forn(j, m){
  54.             double q;
  55.             scanf("%lf", &q);
  56.             a[i].pb(q);
  57.         }
  58.     }
  59.     int h;
  60.     int w;
  61.     scanf("%d%d", &h, &w);
  62.     b.resize(h);
  63.     forn(i, h){
  64.         forn(j, w){
  65.             double q;
  66.             scanf("%lf", &q);
  67.             b[i].pb(q);
  68.         }
  69.     }  
  70.     if(m!=h){
  71.         printf("Operation is undefined for these matrixes\n");
  72.         return 0;
  73.     }
  74.     vector <vector <double> > c(n);
  75.     forn(i, n){
  76.         c[i].resize(w, 0);
  77.         forn(j, w){
  78.             forn(k, m){
  79.                 c[i][j]+=a[i][k]*b[k][j];  
  80.             }
  81.         }
  82.     }
  83.     forn(i, n){
  84.         forn(j, w){
  85.             printf("%2.3lf ", c[i][j]);
  86.         }   printf("\n");
  87.     }
  88.     return 0;
  89. }
  90.  
Advertisement
Add Comment
Please, Sign In to add comment