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 ...
随机推荐
- django中常用到的前端样式
注:这里的样式都是导入bootstrap后经常用到的 1.栅格系统 col-md 中型设备台式电脑(>=992px),以折叠开始,断点以上是水平的.列数量和:12. col-md-offset- ...
- vue 验证码倒计时
//html <div class="input-div" v-show="formData.phone"> <input type=&quo ...
- (转)java调用python脚本
这篇博客旨在吐血分享今天遇到的java调用python脚本遇到的坑,折腾了3个多小时终于可以跑通了,代码超级短,但网上的好多资料都是抄来抄去的,很少有能够直接跑通的,尤其是针对你的python文件中用 ...
- Python几种数据结构内置方法的时间复杂度
参考:https://blog.csdn.net/baoli1008/article/details/48059623 注:下文中,’n’代表容器中元素的数量,’k’代表参数的值,或者参数的数量. 1 ...
- pyc文件是什么【转载】
转自:https://blog.51cto.com/bella41981/2045108 1.概念 pyc文件是py文件编译后生成的字节码文件(byte code).pyc文件经过python解释器最 ...
- iText实现导出pdf文件java代码实现例子
///////////////////////////////////主类////////////////////////////////////////// package com.iText; i ...
- Eclipse+GitHub 提交代码错误 -“rejected - non-fast-forward”
Eclipse Push出现rejected - non-fast-forward错误 在 Push到服务器时有时会出现 rejected - non-fast-forward 错误,这是由于远端发生 ...
- 17.在自适应屏幕里通过JQ来获取宽高并赋给需要的
在自适应屏幕里通过JQ来获取宽高并赋给需要的div. var height = document.documentElement.clientHeight; $(window).height();(同 ...
- 输出调试技巧 PRINTF()
#define PRINTF(...) \ do { \ printf( "%d:%s::",__LINE__, __FUNCTION__);\ printf(__VA_ARGS_ ...
- C++ new运算符
new 分配的数据类型:内置数据类型.自定义数据类型. 如果不成功,则 new 将返回零或引发异常:编写自定义异常处理例程并调用 _set_new_handler运行库函数(以您的函数名称作为其参数) ...