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. 【Origin】工仕途中

    -脚步翩跹,随蝶起舞,翩翩不知所往 晨起脚步催, 蝴蝶迎面飞; 正是春意浓, 三月好风景. -作于二零一六年三月二十八日

  2. XML节点名称中有小数点处理(deal with dot)导致使用xpath时报错解决方法

    <?xml version="1.0"?> <ModifyFiles> <_Layout.cshtml>123456</_Layout.c ...

  3. ./fedora_install_oracle.sh bad interpreter

    错误原因之一很有可能是你的脚本文件是DOS格式的, 即每一行的行尾以\r\n来标识, 其ASCII码分别是0x0D, 0x0A.可以有很多种办法看这个文件是DOS格式的还是UNIX格式的, 还是MAC ...

  4. paper 5:支持向量机系列二: Support Vector —— 介绍支持向量机目标函数的 dual 优化推导,并得出“支持向量”的概念。

    paper 4中介绍了支持向量机,结果说到 Maximum Margin Classifier ,到最后都没有说“支持向量”到底是什么东西.不妨回忆一下上次最后一张图: 可以看到两个支撑着中间的 ga ...

  5. My sql 日期格式化

    DATE_FORMAT() 函数用于以不同的格式显示日期/时间数据. 语法 DATE_FORMAT(date,format) select DATE_FORMAT(NOW(),'%Y-%m-%d %H ...

  6. APP的UI测试要点

    1.文字显示是否正确 比如与需求图片对比是否正确,无错别字 2.对齐方式是否正确 3.图片 图片显示的篇幅不要太大. 4.颜色是否正确 颜色与需求规定的是否一致

  7. struts2 笔记04 杂记

    流程: 1. StrutsPrepareAndExcuteFilter:StrutsPrepareAndExcuteFilter作为前端控制器,是整个Struts2的调度中心. 2. ActionMa ...

  8. autohotkey-【GUI】Switch between Windows of the Same Application

    下面给出了ahk的脚本,但我需要GUI http://superuser.com/questions/435602/shortcut-in-windows-7-to-switch-between-sa ...

  9. linux内核参数优化

    net.ipv4.ip_forward = 0net.ipv4.conf.default.rp_filter = 1net.ipv4.conf.default.accept_source_route ...

  10. jython学习笔记2

    1.%是求余,//是整除的商,**是乘方 abs(var) Absolute value pow(x, y) Can be used in place of ** operator pow(x,y,m ...