Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iomanip>
- #include <iostream>
- #include <functional>
- #include <algorithm>
- #include <math.h>
- #include <cmath>
- #include <string>
- #include <vector>
- #include<set>
- #include<map>
- #include <time.h>
- using namespace std;
- bool isitinside(int a, int b){
- return a >= 0 && a <= 7 && b >= 0 && b < 8;
- }
- int amass[8][8] = { 2 ,3 ,4 ,4 ,4 ,4, 3 ,2,
- 3 ,4, 6, 6, 6 ,6 ,4, 3,
- 4, 6, 8, 8, 8 ,8 ,6, 4
- ,4, 6, 8, 8 ,8, 8, 6, 4,
- 4, 6 ,8, 8, 8, 8, 6, 4,
- 4, 6 ,8 ,8 ,8 ,8 ,6 ,4,
- 3, 4 ,6 ,6 ,6 ,6, 4, 3,
- 2, 3 ,4 ,4, 4, 4, 3, 2,
- };
- void rebuild(int a, int b){
- int uu = b + 2;
- int left = a - 1;
- int r = a + 1;
- int dd = b - 2;
- int u = b + 1, d = b - 1;
- int ll = a - 2, rr = a + 2;
- if (isitinside(left, uu))amass[left][uu]--;;//0 condition
- if (isitinside(left, dd)) amass[left][dd]--;//1 condition
- if (isitinside(r, dd)) amass[r][dd]--;//2 condition
- if (isitinside(r, uu)) amass[r][uu]--;//3condition
- if (isitinside(rr, u)) amass[rr][u]--;//4condition
- if (isitinside(rr, d)) amass[rr][d]--;//5condition
- if (isitinside(ll, u)) amass[ll][u]--;//6condition
- if (isitinside(ll, d)) amass[ll][d]--;//7condition
- }
- int exist[8][8] = { 0 };
- bool check[8][8] = { false };
- int xo, yo;
- bool inside(int a, int b){
- return a >= 0 && a <= 7 && b >= 0 && b < 8&&!check[a][b];
- }
- void output(){
- for (int i = 0; i < 8; i++){
- for (int k = 0; k < 8; k++){
- cout << exist[i][k] << " ";
- }
- cout << endl;
- }
- int yj;
- cin >> yj;
- }
- int sum = 0;
- void solve(int a,int b){
- rebuild(a, b);
- int uu = b + 2;
- int left = a - 1;
- int r = a + 1;
- int dd = b - 2;
- int u = b + 1, d = b - 1;
- int ll = a - 2, rr = a + 2;
- pair<int, int > c[8];
- for (int i = 0; i < 9; i++){
- c[i].second = i;
- c[i].first = 99;
- }
- if (inside(left, uu))c[0].first = amass[left][uu];//0 condition
- if (inside(left, dd))c[1].first = amass[left][dd];//1 condition
- if (inside(r, dd))c[2].first = amass[r][dd];//2 condition
- if (inside(r, uu))c[3].first = amass[r][uu];//3condition
- if (inside(rr, u))c[4].first = amass[rr][u];//4condition
- if (inside(rr, d))c[5].first = amass[rr][d];//5condition
- if (inside(ll, u))c[6].first = amass[ll][u];//6condition
- if (inside(ll, d))c[7].first = amass[ll][d];//7condition
- int cool = 12, count = 12;
- //for (int i = 0; i < 8; i++)cout << c[i].first << " ";
- for (int i = 0; i <= 7; i++){
- if (cool > c[i].first){
- //cout << "kkk;";
- cool = c[i].first;
- count = c[i].second;
- }
- }//cout << "::"<< count;int hh; cin >> hh;
- if (count == 12)output();
- switch (count)
- {case 0:a = left, b = uu;
- break;
- case 1:a = left, b = dd;
- break;
- case 2:a = r, b = dd;
- break;
- case 3:a = r, b = uu;
- break;
- case 4:a = rr, b = u;
- break;
- case 5:a = rr, b = d;
- break;
- case 6:a = ll, b = u;
- break;
- case 7:a = ll, b = d;
- break;
- default:
- break;
- }
- exist[a][b] = sum;
- sum++;
- check[a][b] = true;
- solve(a, b);
- }
- int main(){
- solve(0,0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement