Description

Yaaaay, Haven't you heard the news? Bakaloria results are out! And Reem had very good grades. Finally she can go to IT college and pursue her childhood dream of becoming a great programmer.

Reem is very excited about her college, she already started learning programming. Today she was learning about a very well known problem, the 8-Queens problem (you never saw that coming, didn't you?) she has wrote a program to generate all the possible situations of the queens, but as a novice programmer she found it hard to check whether if these situations are valid. As usual you come to her rescue and offer to help with this hard task!

Now you are stuck with this task: Given the positions of 8 queens on a regular chess board, determine if this situation is valid.

A valid situation is a configuration of the 8 queens where no queen can strike any other queen.

On a standard 8 × 8 chess board, a queen can strike any other queen on it's row, column, or two diagonals.

Input

The first line of input has one integer T the number of test cases your program must process.

Each of the next T lines contains the positions of 8 queens. A position of a queen is described as one character [A - H] (the column of the queen), followed by one number [1 - 8] (the row of the queen)

For example: "A4" represents a queen at the first column and the fourth row.

(see sample input for more details)

Output

For each test case print one line containing the word Valid if the configuration is valid, or Invalid otherwise.

Examples
input
2
A1 B5 C8 D6 E3 F7 G2 H4
C3 E4 C4 E1 C4 F4 A8 G6
output
Valid
Invalid
题意:告诉我们8个棋子的摆放位置,问我们可以这样摆放么
解法:A-Z先变换为1-8,然后根据八皇后的规定判断
#include<bits/stdc++.h>
using namespace std;
struct P
{
int x,y;
}He[100];
char s[10];
set<int>q1,q2;
int main()
{
int t;
cin>>t;
while(t--)
{
for(int i=1;i<=8;i++)
{
cin>>s;
He[i].x=s[0]-'A'+1;
He[i].y=s[1]-'0';
q1.insert(He[i].x);
q2.insert(He[i].y);
//cout<<He[i].x<<" "<<He[i].y<<endl;
}
if(q1.size()==q2.size()&&q1.size()==8)
{
int flag=0;
for(int i=1;i<=8;i++)
{
for(int j=1;j<=8;j++)
{
if(i!=j)
{
if(abs(He[i].x-He[j].x)==abs(He[i].y-He[j].y))
{
flag=1;
break;
}
}
}
}
if(flag)
{
cout<<"Invalid"<<endl;
}
else
{
cout<<"Valid"<<endl;
}
}
else
{
cout<<"Invalid"<<endl;
}
// cout<<q1.size()<<" "<<q2.size()<<endl;
q1.clear(),q2.clear();
}
return 0;
}

  

2015 AlBaath Collegiate Programming Contest B的更多相关文章

  1. 2015 AlBaath Collegiate Programming Contest A

    Description Tamer is traveling with his brother on a long highway. He sees a traffic light at a dist ...

  2. 2015 AlBaath Collegiate Programming Contest(2月14日训练赛)

    A (By ggg): 题意:一个人还有x秒到红绿灯,这个红绿灯有g秒绿灯,y秒黄 灯,r秒红灯,问你到红绿灯的时候是什么灯.值得注意的是绿 灯变黄灯时,第g秒是黄灯了. B (By Anxdada) ...

  3. The 2015 China Collegiate Programming Contest A. Secrete Master Plan hdu5540

    Secrete Master Plan Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Othe ...

  4. The 2015 China Collegiate Programming Contest Game Rooms

    Game Rooms Time Limit: 4000/4000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submi ...

  5. 2015 German Collegiate Programming Contest (GCPC 15) + POI 10-T3(12/13)

    $$2015\ German\ Collegiate\ Programming\ Contest\ (GCPC 15) + POI 10-T3$$ \(A.\ Journey\ to\ Greece\ ...

  6. Gym 100952E&&2015 HIAST Collegiate Programming Contest E. Arrange Teams【DFS+剪枝】

    E. Arrange Teams time limit per test:2 seconds memory limit per test:64 megabytes input:standard inp ...

  7. Gym 100952F&&2015 HIAST Collegiate Programming Contest F. Contestants Ranking【BFS+STL乱搞(map+vector)+优先队列】

    F. Contestants Ranking time limit per test:1 second memory limit per test:24 megabytes input:standar ...

  8. The 2015 China Collegiate Programming Contest L. Huatuo's Medicine hdu 5551

    Huatuo's Medicine Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others ...

  9. The 2015 China Collegiate Programming Contest K Game Rooms hdu 5550

    Game Rooms Time Limit: 4000/4000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total ...

随机推荐

  1. 两条直线(蓝桥杯)二分枚举+RMQ

    算法提高 两条直线   时间限制:1.0s   内存限制:256.0MB        问题描述 给定平面上n个点. 求两条直线,这两条直线互相垂直,而且它们与x轴的夹角为45度,并且n个点中离这两条 ...

  2. 求树的重心(POJ1655)

    题意:给出一颗n(n<=2000)个结点的树,删除其中的一个结点,会形成一棵树,或者多棵树,定义删除任意一个结点的平衡度为最大的那棵树的结点个数,问删除哪个结点后,可以让平衡度最小,即求树的重心 ...

  3. linux环境变量与本地变量

    两者不同的是. 环境变量可以在shell的子进程中使用, 而本地变量不同. 每当连接上服务器时,服务器就会通过帐号密码运行一个SHELL,我们所做的工作都在这个SHELL上,特殊方法除外(如,守护进程 ...

  4. php setcookie(name, value, expires, path, domain, secure) 参数详解

    setcookie() 定义一个和其余的 HTTP 标头一起发送的 cookie.和其它标头一样,cookie 必须在脚本的任何其它输出之前发送(这是协议限制).这 需要将本函数的调用放到任何输出之前 ...

  5. php获取文件后缀名格式

    function get_extension($file) { substr(strrchr($file, '.'), 1); } 第2种方法: function get_extension($fil ...

  6. 动画--过渡属性 transition-property

    早期在Web中要实现动画效果,都是依赖于JavaScript或Flash来完成.但在CSS3中新增加了一个新的模块transition,它可以通过一些简单的CSS事件来触发元素的外观变化,让效果显得更 ...

  7. mac工具-解析json visualJSON和JSON Accelerator这两款工具

  8. SQL Server数据库的三种恢复模式:简单恢复模式、完整恢复模式和大容量日志恢复模式(转载)

    SQL Server数据库有三种恢复模式:简单恢复模式.完整恢复模式和大容量日志恢复模式: 1.Simple 简单恢复模式, Simple模式的旧称叫”Checkpoint with truncate ...

  9. 项目中的一个JQuery ajax实现案例

    /**  * brief 这些代码用于在线制图中 attention author <list of authors> <date> begin modify by  * nu ...

  10. linux设备驱动归纳总结(十二):简单的数码相框【转】

    本文转载自:http://blog.chinaunix.net/uid-25014876-id-116926.html linux设备驱动归纳总结(十二):简单的数码相框 xxxxxxxxxxxxxx ...