Advertisement
jeff69

Homework[Jeff_Badour]

Mar 21st, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
4CS 2.95 KB | None | 0 0
  1.  
  2. #include <iomanip>
  3. #include <iostream>
  4. #include <functional>
  5. #include <algorithm>
  6. #include <math.h>
  7. #include <cmath>
  8. #include <string>
  9. #include <vector>
  10. #include<set>
  11. #include<map>
  12. #include <time.h>
  13.  
  14.  
  15. using namespace std;
  16. bool isitinside(int a, int b){
  17.     return a >= 0 && a <= 7 && b >= 0 && b < 8;
  18. }
  19. int amass[8][8] = { 2 ,3 ,4 ,4 ,4 ,4, 3 ,2,
  20.         3 ,4, 6, 6, 6 ,6 ,4, 3,
  21.         4, 6, 8, 8, 8 ,8 ,6, 4
  22.         ,4, 6, 8, 8 ,8, 8, 6, 4,
  23.         4, 6 ,8, 8, 8, 8, 6, 4,
  24.         4, 6 ,8 ,8 ,8 ,8 ,6 ,4,
  25.         3, 4 ,6 ,6 ,6 ,6, 4, 3,
  26.         2, 3 ,4 ,4, 4, 4, 3, 2,
  27.     };
  28.  
  29. void rebuild(int a, int b){
  30.     int uu = b + 2;
  31.     int left = a - 1;
  32.     int r = a + 1;
  33.     int dd = b - 2;
  34.     int u = b + 1, d = b - 1;
  35.     int ll = a - 2, rr = a + 2;
  36.     if (isitinside(left, uu))amass[left][uu]--;;//0 condition
  37.     if (isitinside(left, dd)) amass[left][dd]--;//1 condition
  38.     if (isitinside(r, dd))  amass[r][dd]--;//2 condition
  39.     if (isitinside(r, uu)) amass[r][uu]--;//3condition
  40.     if (isitinside(rr, u))  amass[rr][u]--;//4condition
  41.     if (isitinside(rr, d))  amass[rr][d]--;//5condition
  42.     if (isitinside(ll, u))  amass[ll][u]--;//6condition
  43.     if (isitinside(ll, d)) amass[ll][d]--;//7condition
  44. }
  45. int exist[8][8] = { 0 };
  46. bool check[8][8] = { false };
  47. int xo, yo;
  48. bool inside(int a, int b){
  49.     return a >= 0 && a <= 7 && b >= 0 && b < 8&&!check[a][b];
  50. }
  51. void output(){
  52.     for (int i = 0; i < 8; i++){
  53.         for (int k = 0; k < 8; k++){
  54.             cout << exist[i][k] << " ";
  55.         }
  56.         cout << endl;
  57.     }
  58.     int yj;
  59.     cin >> yj;
  60. }
  61. int sum = 0;
  62. void solve(int a,int b){
  63.     rebuild(a, b);
  64.     int uu = b + 2;
  65.     int left = a - 1;
  66.     int r = a + 1;
  67.     int dd = b - 2;
  68.     int u = b + 1, d = b - 1;
  69.     int ll = a - 2, rr = a + 2;
  70.     pair<int, int > c[8];
  71.     for (int i = 0; i < 9; i++){
  72.         c[i].second = i;
  73.         c[i].first = 99;
  74.     }
  75.     if (inside(left, uu))c[0].first = amass[left][uu];//0 condition
  76.     if (inside(left, dd))c[1].first = amass[left][dd];//1 condition
  77.     if (inside(r, dd))c[2].first = amass[r][dd];//2 condition
  78.     if (inside(r, uu))c[3].first = amass[r][uu];//3condition
  79.     if (inside(rr, u))c[4].first = amass[rr][u];//4condition
  80.     if (inside(rr, d))c[5].first = amass[rr][d];//5condition
  81.     if (inside(ll, u))c[6].first = amass[ll][u];//6condition
  82.     if (inside(ll, d))c[7].first = amass[ll][d];//7condition
  83.     int cool = 12, count = 12;
  84.     //for (int i = 0; i < 8; i++)cout << c[i].first << " ";
  85.    
  86.    
  87.     for (int i = 0; i <=  7; i++){
  88.         if (cool > c[i].first){
  89.             //cout << "kkk;";
  90.             cool = c[i].first;
  91.             count = c[i].second;
  92.         }
  93.     }//cout << "::"<< count;int hh; cin >> hh;
  94.     if (count == 12)output();
  95.     switch (count)
  96.     {case 0:a = left, b = uu;
  97.     break;
  98.     case 1:a = left, b = dd;
  99.         break;
  100.     case 2:a = r, b = dd;
  101.         break;
  102.     case 3:a = r, b = uu;
  103.         break;
  104.     case 4:a = rr, b = u;
  105.         break;
  106.     case 5:a = rr, b = d;
  107.         break;
  108.     case 6:a = ll, b = u;
  109.         break;
  110.     case 7:a = ll, b = d;
  111.         break;
  112.     default:
  113.         break;
  114.     }
  115.    
  116.     exist[a][b] = sum;
  117.     sum++;
  118.     check[a][b] = true;
  119.     solve(a, b);
  120.  
  121.  
  122.  
  123. }
  124. int main(){
  125.    
  126.     solve(0,0);
  127.    
  128.  
  129.  
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement