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. npm install webpack -g

    npm install webpack -g   全局安装webpack

  2. docker知识点

    1  安装 http://www.runoob.com/docker/centos-docker-install.html 2  dockerhub官网找到 emqttd 执行 docker pull ...

  3. Spring Boot下的lombok安装以及使用简介

    引言:lombok是一套代码模板解决方案,将极大提升开发的效率,这里介绍给大家使用. 1. Lombok lombok是一个可以通过简单的注解的形式来帮助我们简化消除一些必须有但显得很臃肿的 Java ...

  4. python 根据字符串动态的生成变量名并且赋值

    Python 动态的创建变量 一.子符串的形式 这是在今天的一个项目中,发现需要动态的创建很多变量.每个变量对应的值的来源都相同.在网上看了些资料,研究出了这个动态创建变量的牛逼方法. 所用的方法就是 ...

  5. ssh 的认证原理

    SSH:Secure Shell,是一种网络安全协议,主要用于登录远程计算机的加密过程. 登录方式主要有两种: 1.基于用户密码的登录方式:   加密原理:   当服务器知道用户请求登录时,服务器会把 ...

  6. “脚踢各大Python Web框架”,Sanic真有这能耐么?

    在Github上,Sanic第一句介绍语就是: "Sanic is a Flask-like Python 3.5+ web server that's written to go fast ...

  7. ODBC是什么

    ODBC(Open Database Connectivity,开放数据库互连)是微软公司开放服务结构(WOSA,Windows Open Services Architecture)中有关数据库的一 ...

  8. 再次 WebAssembly 技术探讨

    上次说到你可以将C代码编译成web调用的js文件,当时,很兴奋.哈哈,我也误以为是系统级别的C编程呢! 哎,今天,告诉你一个残酷的事实是,只是C语言级别,不是系统级别.因为WebAssembly目标是 ...

  9. vue+element-ui中的表单验证(电话等等)

    1. 2. 3. ============================================================上代码============================ ...

  10. python爬虫-基础入门-爬取整个网站《1》

    python爬虫-基础入门-爬取整个网站<1> 描述: 使用环境:python2.7.15 ,开发工具:pycharm,现爬取一个网站页面(http://www.baidu.com)所有数 ...