Rooks NOJ 1390
来源:互联网 发布:windows vista和xp 编辑:程序博客网 时间:2024/05/17 05:53
Rooks
总提交 : 61 测试通过 : 42
题目描述
Jake and Sully are playing around with a chessboard one night after working with their avatars all
day. They decide it would be interesting to place some rooks on the chessboard in a way that no rook
can threaten another rook. Since rooks move along rows and columns, this means two rooks may not
be on the same row or column. Your goal is to write a program to determine whether any rooks are
threatened.
输入
Chessboards are 8x8 boards with positions between (1,1) and (8,8). The input begins with the
number of chess boards. Each chessboard is on a separate line and begins with the number of rooks,
followed by the column and row positions of each rook.
输出
For each chessboard, your program should output the words ”SAFE” or ”NOT SAFE” on a
single line.
样例输入
2
3 1 1 2 6 8 8
2 2 3 1 3
样例输出
SAFE
NOT SAFE
提示
undefined
水题就不多说什么了==
实现代码:
<span style="font-size:12px;">#include<iostream>#include<cstdlib>#include<cstdio>using namespace std;int t,n;int main(){ scanf("%d",&t); while(t--) { scanf("%d",&n); int flag=1; int *a=new int[n+1],*b=new int[n+1]; for(int i=0;i<n;i++) { scanf("%d%d",&a[i],&b[i]); for(int j=0;j<i&&flag==1;j++) { if(flag==1&&(a[i]==a[j])||(b[i]==b[j])) { flag=0; } } } if(flag==1) { printf("SAFE\n"); } else printf("NOT SAFE\n"); }}</span>
- Rooks NOJ 1390
- 南邮 OJ 1390 Rooks
- Noj
- Fabled Rooks
- A - Rooks
- Fabled Rooks
- Fabled Rooks
- HDU3160 Rooks
- UVA11134_Fabled Rooks
- Fabled Rooks
- A - Rooks
- NOJ 176
- NOJ 175
- NOJ 179
- NOJ 141
- NOJ 214
- NOJ 147
- NOJ 1242
- 第5周项目3-用多文件组织多个类的程序
- C语言运算符的结合性
- 伙伴算法 (Buddy Algorithm)简单描诉和自己的简单实现
- Launcher3 源码分析(一) 整体结构及核心类
- 【剑指offer】第四题 替换空格
- Rooks NOJ 1390
- shell中数组的应用
- VMware虚拟机中如何安装VMWare-Tools详解
- POJ刷题(2013)
- 使用repo和git下载android源码 和 相关解释
- 五大常用算法之四:回溯法
- python 多线程就这么简单
- 点击按钮弹出遮罩层背景和居于屏幕中间的弹出窗口(结合阿聪世家适当修改)
- 黑马程序员——C语言基础语法、基本运算理论