Don't like ads? PRO users don't see any ads ;-)

Untitled

By: kooinam on Jun 22nd, 2012  |  syntax: None  |  size: 0.66 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int ky(int input[3][3]){
  5.         int sum[3][3] = {0};
  6.         int a[3][3] = {0};
  7.         int res = 1000000;
  8.         for(int i = 0; i < 3; i++){
  9.                 for(int j = 0; j < 3; j++){
  10.                         a[i][j] = input[(i+1)%3][j]+input[(i+2)%3][j];
  11.                 }
  12.         }
  13.         for(int i = 0; i < 3; i++){
  14.                 for(int j = 0; j < 3; j++){
  15.                         sum[i][j] = min(a[(i+1)%3][(j+1)%3]+a[(i+2)%3][(j+2)%3],a[(i+1)%3][(j+2)%3]+a[(i+2)%3][(j+1)%3]);
  16.                         sum[i][j] += a[i][j];
  17.                 }
  18.         }
  19.         for(int i = 0; i < 3; i++){
  20.                 for(int j = 0; j < 3; j++){
  21.                         res = min((int)res,sum[i][j]);
  22.                 }
  23.         }
  24.         return res;
  25. }
  26.  
  27. int main() {
  28.         int arr[3][3] = {{5,10,5},{20,10,5},{10,20,10}};
  29.         cout << ky(arr);
  30.     return 0;
  31. }