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;
}