Kattis之旅——Eight Queens
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.

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的更多相关文章
- Kattis之旅——Prime Reduction
A prime number p≥2 is an integer which is evenly divisible by only two integers: 1 and p. A composit ...
- Kattis之旅——Chinese Remainder
Input The first line of input consists of an integers T where 1≤T≤1000, the number of test cases. Th ...
- Kattis之旅——Fractional Lotion
Freddy practices various kinds of alternative medicine, such as homeopathy. This practice is based o ...
- Kattis之旅——Factovisors
The factorial function, n! is defined thus for n a non-negative integer: 0! = 1 n! = n * (n-1)! (n & ...
- Kattis之旅——Rational Arithmetic
Input The first line of input contains one integer, giving the number of operations to perform. Then ...
- Kattis之旅——Number Sets
You start with a sequence of consecutive integers. You want to group them into sets. You are given t ...
- Kattis之旅——Divisible Subsequences
Given a sequence of positive integers, count all contiguous subsequences (sometimes called substring ...
- Kattis之旅——Prime Path
The ministers of the cabinet were quite upset by the message from the Chief of Security stating that ...
- Kattis之旅——Inverse Factorial
题目意思就是已知n的阶乘,求n. 当输入的阶乘小于10位数的时候,我们可以用long long将字符串转化成数字,直接计算. 而当输入的阶乘很大的时候,我们就可以利用位数去大概的估计n. //Asim ...
随机推荐
- Element-table-formatter格式化数据
1.formatter 用来格式化内容 对table的值进行处理.Function(row, column, cellValue, index){} 使用formatter需要注意以下几点: ...
- ES6封装原生ajax请求
http (data) { return new Promise((resolve, reject) => { var xhr = new XMLHttpRequest(); xhr.onrea ...
- JAVA基础——时间Date类型转换
在java中有六大时间类,分别是: 1.java.util包下的Date类, 2.java.sql包下的Date类, 3.java.text包下的DateFormat类,(抽象类) 4.java.te ...
- 用python 替换文件中的git地址
有个需求要替换文件中git地址,要替换成的git地址是一个变量 本来想用sed替换但是git地址中有斜杠符号 需要转义,提前知道还好弄,如果是变量就不好处理了 #!/usr/bin/python3 # ...
- async await的用法
const fs = require('fs'); const readFile = function (fileName) { return new Promise(function (resolv ...
- MongoDB--预备
- Node.js进击基础一(http)
URL:统一资源定位符,偏重定位,是URI的子集,例如网址.URL一定是URI,但URI 不一定是URL.规则:只能用英文阿拉伯数字某些符号等,如果有文字就必须编码. URI:统一资源标识符,偏重标识 ...
- iOS 第三方框架-Masonry
介绍地址:http://www.cocoachina.com/ios/20141219/10702.html 官网:https://github.com/SnapKit/Masonry 记住:一定要先 ...
- cocos2dx 游戏plist与png完美切成小图python代码
首先需要一份python的切图程序: #python2.5 unpack_plist.py birdfly #! /usr/lical/bin/python import os,sys from xm ...
- Navicat Premium 安装与激活破解版简单操作 (原)
首先下载navicate程序以及破解文件,这里一并存到了百度网盘直接下载即可 链接:https://pan.baidu.com/s/11ptFmsV1o3B5oB00zm2NdQ 密码:yw82 解压 ...