博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Kattis之旅——Eight Queens
阅读量:5234 次
发布时间:2019-06-14

本文共 1804 字,大约阅读时间需要 6 分钟。

In the game of chess, the queen is a powerful piece. It can attack by moving any number of spaces in its current row, in its column or diagonally.

In the eight queens puzzle, eight queens must be placed on a standard 8×8

chess board so that no queen can attack another. The center figure below shows an invalid solution; two queens can attack each other diagonally. The figure on the right shows a valid solution. Given a description of a chess board, your job is to determine whether or not it represents a valid solution to the eight queens puzzle.

\includegraphics[width=0.7\textwidth ]{chess}
Figure 1: Queen movement (left), invalid solution (center), valid solution (right).

Input

Input will contain a description of a single chess board, given as eight lines of eight characters each. Input lines will consist of only the characters ‘.’ and ‘*’. The ‘.’ character represents an empty space on the board, and the ‘*’ character represents a queen.

Output

Print a single line of output. Print the word “valid” if the given chess board is a valid solution to the eight queens problem. Otherwise, print “invalid”.

Sample Input 1 Sample Output 1
*.........*.........*.........*..*.............*.....*.....*....
invalid
Sample Input 2 Sample Output 2
*.............*.....*..........*.*.........*.........*....*.....
valid

给出一个图,判断是否符合8皇后的摆法。

题目很简单,自己错的一塌糊涂。

#include 
using namespace std;struct point{
  int x,y; }; int absolutey(int z) { if(z<0){
return z*-1;} else{
return z;}} bool ceksinggung(point a, point b) { if(a.x==b.x||a.y==b.y||(a.x+a.y)==(b.x+b.y)||(a.x-a.y)==(b.x-b.y)||(a.y-a.x)==(b.y-b.x)) return true; else return false;}int main() { vector
vp; for(int i=0;i<8;i++) { string s; cin>>s; for(int j=0;j

 

转载于:https://www.cnblogs.com/Asimple/p/6744635.html

你可能感兴趣的文章
图的深度优先遍历
查看>>
C# 之 提高WebService性能大数据量网络传输处理
查看>>
md5sum命令详解
查看>>
[bzoj1004] [HNOI2008] Cards
查看>>
应该是实例化对象的没有对属性赋值时,自动赋值为null,但不是空指针对象引用...
查看>>
原生HttpClient详细使用示例
查看>>
几道面试题
查看>>
Factory Design Pattern
查看>>
python中贪婪与非贪婪
查看>>
guava API整理
查看>>
无锁编程笔记
查看>>
jquery mobile
查看>>
如何在vue单页应用中使用百度地图
查看>>
Springboot使用步骤
查看>>
Spring属性注入
查看>>
Springboot-配置文件
查看>>
Springboot-日志框架
查看>>
SpringBoot-thymeleaf
查看>>
P1908-逆序对
查看>>
P1192-台阶问题
查看>>