Submission #1757736
Source Code Expand
#include <iostream> #include <vector> #include <queue> using namespace std; using vc = vector<char>; using vvc = vector<vector<char>>; int dic[5] = {1,1,-1,-1,1}; bool inside(int a){ return ((a >= 0) && (a < 8)) ; } bool paint(int y,int x,vvc& arr){ arr[y][x] = '.'; for(int k = 0; k < 8; k++){ if(arr[k][x] == 'Q' || arr[y][k] == 'Q') return true; arr[k][x] = arr[y][k] = ' '; } for(int i = 0; i < 4; i++){ for(int j = 0; j < 8; j++){ if(inside(y+dic[i]*j) && inside(x+dic[i+1]*j)){ if(arr[y+dic[i]*j][x+dic[i+1]*j] == 'Q') return true; arr[y+dic[i]*j][x+dic[i+1]*j] = ' '; } } } arr[y][x] = 'Q'; return false; } void output(vvc& now){ for(int i = 0; i < 8; i++){ for(int j = 0; j < 8; j++){ if(now[i][j] == 'Q') cout << 'Q'; else cout << '.';//. } cout << endl; } } void display(vvc& now){ cout << "-----------" << endl; for(int i = 0; i < 8; i++){ for(int j = 0; j < 8; j++){ cout << now[i][j]; } cout << endl; } cout << "-----------" << endl << endl; } int main(void){ vvc arr(8,vc(8)); for(int i = 0; i < 8; i++) for(int j = 0; j < 8; j++){ cin >> arr[i][j]; } for(int i = 0; i < 8; i++) for(int j = 0; j < 8; j++) if(arr[i][j] == 'Q'){ if(paint(i,j,arr)){ cout << "No Answer" << endl; return 0; } } stack<vvc> q; q.push(arr); //64 //64-32+3 = 32 //35 - 32 + 10 = 16 //13 - 32 + 20 = 8 //4 //2 //1 //2^20 while(!q.empty()){//O(8*8*8*4 = 2048 = 2^11) vvc now = q.front(); q.pop(); //display(now); int answer = 0; for(int i = 0; i < 8; i++) for(int j = 0; j < 8; j++){ if( now[i][j] == '.' ){ vvc next = now; if(paint(i,j,next)){ continue; } q.push(next); }else{ if(now[i][j] == 'Q') answer++; } } if(answer == 8){ output(now); return 0; } } cout << "No Answer" << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | C - パズルのお手伝い |
User | nasatame |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 2702 Byte |
Status | CE |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:81:5: error: ‘stack’ was not declared in this scope stack<vvc> q; ^ ./Main.cpp:81:14: error: expected primary-expression before ‘>’ token stack<vvc> q; ^ ./Main.cpp:81:16: error: ‘q’ was not declared in this scope stack<vvc> q; ^