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.

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 <bits/stdc++.h>
using namespace std; struct point{
  int x,y;
};
int absolutey(int z) {
if(z<){return z*-;}
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<point> vp;
for(int i=;i<;i++) {
string s;
cin>>s;
for(int j=;j<s.length();j++) {
if(s.substr(j,)=="*") {
point temp;
temp.x=j+;
temp.y=i+;
vp.push_back(temp);
}
}
}
bool singgung=false;
for(int i=;i<;i++) {
for(int j=;j<;j++) {
if(i!=j) {
singgung=singgung||ceksinggung(vp[i],vp[j]);
}
}
}
  if(singgung)cout<<"invalid\n";
  else cout<<"valid\n";
  return ;
}

Kattis之旅——Eight Queens的更多相关文章

  1. Kattis之旅——Prime Reduction

    A prime number p≥2 is an integer which is evenly divisible by only two integers: 1 and p. A composit ...

  2. Kattis之旅——Chinese Remainder

    Input The first line of input consists of an integers T where 1≤T≤1000, the number of test cases. Th ...

  3. Kattis之旅——Fractional Lotion

    Freddy practices various kinds of alternative medicine, such as homeopathy. This practice is based o ...

  4. Kattis之旅——Factovisors

    The factorial function, n! is defined thus for n a non-negative integer: 0! = 1 n! = n * (n-1)! (n & ...

  5. Kattis之旅——Rational Arithmetic

    Input The first line of input contains one integer, giving the number of operations to perform. Then ...

  6. Kattis之旅——Number Sets

    You start with a sequence of consecutive integers. You want to group them into sets. You are given t ...

  7. Kattis之旅——Divisible Subsequences

    Given a sequence of positive integers, count all contiguous subsequences (sometimes called substring ...

  8. Kattis之旅——Prime Path

    The ministers of the cabinet were quite upset by the message from the Chief of Security stating that ...

  9. Kattis之旅——Inverse Factorial

    题目意思就是已知n的阶乘,求n. 当输入的阶乘小于10位数的时候,我们可以用long long将字符串转化成数字,直接计算. 而当输入的阶乘很大的时候,我们就可以利用位数去大概的估计n. //Asim ...

随机推荐

  1. 微信小程序 - 表单验证插件WxValidate使用

    插件下载地址及官方文档:https://github.com/skyvow/wx-extend 具体的WxValidate.js文件的位置在wx-extend/src/assets/plugins/w ...

  2. 网络基础之2——TCP/IP参考模型

    本内容主要来源于<看透Spring MVC源码分析与实践——韩路彪>一书 BS结构网络传输的分解方式有两种: 1.OSI参考模型. 2.TCP/IP参考模型. OSI和TCP/IP分层模型 ...

  3. tf实现LSTM时rnn.DropoutWrapper

    转自:https://blog.csdn.net/abclhq2005/article/details/78683656 作者:abclhq2005 1.概念介绍 所谓dropout,就是指网络中每个 ...

  4. python requests http请求

    导入模块 import requests import json header = {'Content-Type': 'application/json'} data = {"} data ...

  5. PHP处理大文件下载

    <?php /** * Created by PhpStorm. * User: Kung * Date: 15-10-21 * Time: 下午8:00 */ set_time_limit(0 ...

  6. 从零开始一起学习SLAM | 为什么要学SLAM?

    在<零基础小白,如何入门计算机视觉?>中我提到过,计算机视觉的研究目前主要分为两大方向:基于学习的方法和基于几何的方法.其中基于学习的方法最火的就是深度学习,而基于几何方法最火的就是视觉S ...

  7. HDU 3306 Another kind of Fibonacci(矩阵+ll超时必须用int&输入必须取模&M必须是int类型)

    Another kind of Fibonacci [题目链接]Another kind of Fibonacci [题目类型]矩阵+ll超时必须用int&输入必须取模&M必须是int ...

  8. Oracle中找出用户的上次登录时间

    可以使用如下sql语句: select t1.username,t1.logon_time last_logon_time,t2.account_status,created 账号创建时间 from ...

  9. 清华操作系统实验--80x86汇编基础

    前言 80x86架构里,因为历史原因字是16位的,因此在汇编指令中用后缀-b,-w,-l来表示操作数是字节 字 或是双字 C声明 Intel数据类型 汇编代码后缀 大小(字节) char 字节 b 1 ...

  10. django admin 处理文本换行空格

    使用 linebreaks filter <p>{{ blogpassage.content|linebreaksbr }}<p>