Advertisement
|
[x]
Posted via EE Mobile
|
||
Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again. |
||
| 09/04/2008 at 05:02PM PDT, ID: 23704740 |
|
[x]
Attachment Details
|
||
|
[x]
The Solution Rating System
|
||
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
Your Input Matters If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support. Thank you! |
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: |
#include <cstdlib>
#include <iostream>
using namespace std;
void mapout(int);
bool comptwo(int[2], int[2]);
bool checkall();
int placeq(int,int,int);
void printmap();
int pathnum=1; //how many queens are on the board right now?
int queens[8][2]={}; //the set of queens. I used a 8x2 table (even though the first column will always be the same, 1-8) so that the program is expandable.
int xplace;
int yplace;
int nq;
int main(void)
{
int hits=0;
while(hits<1){ //this is if we want to find one result.
for (int row=1;row<9;row++){
int stopit=0;
for (int col=1;col<9 & stopit<1;col++){
placeq(row,col,pathnum);
pathnum++;
if (checkall()==true){
stopit=1;
pathnum++;
}
pathnum--;
}
if (stopit==0){
pathnum--;
row--;
}
}
}
printmap();
}
bool checkall(){
int compareworks;
for (int j=1;j<pathnum+1;j++){
for (int i=1;i<pathnum+1;i++){
compareworks=comptwo(queens[i],queens[j]);
if (compareworks==0 & j!==i){
return false;
}
}
}
}
bool comptwo(c1[], c2[]){
if (c1[1]==c2[1]||c1[2]==c2[2]){ //horizontal and vertical check
return false;
}
if (c1[1]+c1[2]==c2[1]+c2[2]){ //diagonal down-left to up-right
return false;
}
if (c1[2]-c1[1]==c2[2]-c2[1]){ //diagonal down-right to up-left
return false;
}
return true;
}
void mapout(place){
//some really basic but long code went here...
}
void printmap(){
for (int i=1; i<9; i++){
for (int j=1; j<9; j++){
if queens[j][1]==i{
mapout(queens[j][2]);
}
}
}
}
int placeq(xplace,yplace,nq){
queens[nq][1]=xplace;
queens[nq][2]=yplace;
pathnum=nq;
return 1;
}
|