zoukankan      html  css  js  c++  java
  • Rooks NOJ 1390

    Rooks

    时间限制(普通/Java) : 1000 MS/ 3000 MS          运行内存限制 : 65536 KByte
    总提交 : 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
    ");
            }
            else
                printf("NOT SAFE
    ");
        }
    }</span>

    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    获取Web.config的内容
    VS2013打开2008的项目
    Win7配置IIS7
    JavaScript通知浏览器,更改通知数目
    高分屏显示模糊修复工具
    Linux下使用 xrandr 命令设置屏幕分辨率
    虚拟机VMware怎么完全卸载干净,如何彻底卸载VMware虚拟机
    虚拟机安装VMware Tools
    网站测速、ping
    有名管道的非阻塞设置
  • 原文地址:https://www.cnblogs.com/Tobyuyu/p/4965534.html
Copyright © 2011-2022 走看看