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 ...
随机推荐
- Elemet-技巧
<el-table-column prop="> </el-table-column> 效果: append-to-body 解决el-dialog 弹窗遮罩为题 & ...
- (转)springboot全局处理异常(@ControllerAdvice + @ExceptionHandler)
1.@ControllerAdvice 1.场景一 在构建RestFul的今天,我们一般会限定好返回数据的格式比如: { "code": 0, "data": ...
- (转)Fabric CA环境的集成
PS:因为我部署的是集群(4peer+1order),需要为order,org1,org2分别建立一个CA,拿org1使用举例,获取org1根证书私钥名称:PRIVATE_KEY.sh #!/bin/ ...
- MySQL数据类型--与MySQL零距离接触2-8查看数据表
SHOW COLUMNS FROM tb_name 写入列之后,需要写入行,也就是记录:INSERT 插入记录:INSERT [INTO] tbl_name [(col_name,...)] V ...
- cocos2d JS-(JavaScript) 静态方法的例子
function User(name, age) { this.name = name; this.age = age; } var user = new User('angela',26); Use ...
- end to end
深度学习中的end to end是什么意思? 端到端就是输入一个数据进入模型,然后模型直接可以输出你想要的结果,也就是一体性. 简单讲就是,Input--->系统(这里指神经网络)---> ...
- Python记录8:函数的嵌套
#函数的嵌套分为两类:# 1.函数的嵌套定义: 在函数内部又定义了一个函数# def foo():# x=1# # print(x)# def bar():# print('from bar')## ...
- net npoi将List<实体>导出excel的最简单方法
只是临时导数据用的.方便.最基本的方法, [HttpGet] [Route("ExportEnterprise")] public BaseResponse ExportEnter ...
- mysql优化(二)
一.客户端分担. 1.大量的复杂的运算放在客户端处理. 什么是复杂运算,一般我认为是一秒钟CPU只能做10万次以内的运算.如含小数的对数及指数运算.三角函数.3DES及BASE64数据加密算法等等.如 ...
- java中的锁之Lock接口与Condition接口
一.Lock源码. 1.是一个接口.一共有6个方法. 2.方法详细如下: (1)当前线程尝试获取锁.结果分两种情况,一是成功获取到锁,则返回:二是获取锁失败,则一直等待.不响应中断请求. (2)当前线 ...