UVALive 7097 Growing Rectangular Spiral

Sample Input 3 1 1 1 2 3 5 3 8 4

Sample Output 1 NO PATH 2 2 3 5 3 6 1 2 3 9 10 11

题意:给定一个第一象限的点,求到达这个点的最短长度。(线段按右上左下,每次必须最少大于前一次一个单位)

思路:找规律易得,如果x=y无法达到,如果x<y,通过两次即可达到。如果x>y,前三次一定是1,2,3,第四次不确定,但是第五次可以通过x的坐标计算得到第五次=x+2,则第六次为x+3。解方程得到第四次x-y+5。最后,判断一下各条边是否符合条件。

#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
int a[10],sum,flag;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,x,y;
        cin>>n>>x>>y;
        if(x==y)
        {
            cout<<n<<" NO PATH"<<endl;
        }
        else if(x<y)
        {
            cout<<n<<" 2 "<<x<<" "<<y<<endl;
        }
        else
        {
            if(x-y+5>3&&x-y+5<x+2)
                cout<<n<<" 6 1 2 3 "<<x-y+5<<" "<<x+2<<" "<<x+3<<endl;
            else
                cout<<n<<" NO PATH"<<endl;
        }
    }
    return 0;
}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值