UVA 167,The Sultan's Successors
来源:互联网 发布:3d人像建模软件 编辑:程序博客网 时间:2024/06/11 21:56
题目:八皇后问题的基础上输入每个格子上的数值。问哪一组数的和最小
#include <cstdio>
#include <string.h>
#include <cstdlib>
#include <cmath>
#include <ctgmath>
#include <iostream>
#include <vector>
#include <algorithm>
using namespacestd;
int main()
{
int xunhuan;
cin>> xunhuan;
while(xunhuan--){
//每个格子的数值输入
int num[8][8];
for(int m =0; m < 8; m++){
for(int n =0; n < 8; n++){
cin>>num[m][n];
}
}
int t =1;
int a[8] = {0};
int b[15] = {0};
int c[15] = {0};
int j =0,i=0;
int temp =0;
vector<int> m;
vector<int>::iterator it;
vector<int> sum;
while(1){
for(i =0; i <= 7; i ++){
for(j =0; j <= 7; j ++){
if((a[j]==0) && (b[i+j]==0) && (c[i-j+7]==0) ){//这一点可以有皇后
m.push_back(j);
a[j]=1;
b[i+j]=1;
c[i-j+7]=1;
break;
}
}
//如果走完了还没有位置
if(j ==8){
Next_One: while(1){
if(i >=0){
i--;
temp = m[i];
//删除原来皇后的记录
a[temp]=0;
b[i+temp]=0;
c[i-temp+7]=0;
m.pop_back();
for(j = temp +1; j <=7; j ++){
if((a[j]==0) && (b[i+j]==0) && (c[i-j+7]==0) ){//这一点可以有皇后
m.push_back(j);
a[j]=1;
b[i+j]=1;
c[i-j+7]=1;
break;
}
}
if(j !=8) break;
}
}
}
}
//计算和
int sumnum =0;int ii =0;
for(int q =0; q < 8; q++){
sumnum += num[ii++][m[q]];
}
sum.push_back(sumnum);
t++;
if(t==93)break;
goto Next_One;
}
// goto Next_One;
sort(sum.begin(), sum.end());
printf("%5d\n",sum[91]);
}
return0;
}
- UVa 167 - The Sultan's Successors
- Uva 167 The Sultan's Successors
- uva 167 - The Sultan's Successors
- uva 167 - The Sultan's Successors
- UVa 167 - The Sultan's Successors
- Uva-167-The Sultan's Successors
- uva 167 - The Sultan's Successors
- UVa 167 - The Sultan's Successors
- uva 167 - The Sultan's Successors
- uva 167 The Sultan's Successors
- uva 167 The Sultan's Successors
- UVa 167 - The Sultan's Successors
- UVa 167 - The Sultan's Successors
- UVa 167 - The Sultan's Successors
- UVA 167 - The Sultan's Successors
- UVA - 167 The Sultan's Successors
- UVA - 167 The Sultan's Successors
- uva 167 The Sultan's Successors 搜索
- HTML和HTML5的区别
- GhostView
- makefile伪目标理解
- 面向对象继承-限制范围的拖拽
- RxJava的基本用法
- UVA 167,The Sultan's Successors
- Hadoop学习笔记之flume Nginx日志收集到HBase
- 地宫取宝 蓝桥杯试题
- Yii中where方法使用
- fopen打开文件时,路径中包含中文
- Python Mako模版之页面继承
- ARM64 el1_irq 处理
- 求两个数的最大公约数问题
- Flex datagrid itemrenderer刷新显示错乱问题