Growing Rectangular Spiral

题目描述

A growing rectangular spiral is a connected sequence of straightline segments starting at the origin. The fi rst segment goes right (positive x direction). The next segment goes up (positive y direction). The next segment goes left (negative x direction). The next segment goes down (negative y direction) and the sequence of directions repeats. Each segment has integer length and each segment is at least one unit longer than the previous segment. In the spiral on the right, the segment lengths are 1, 2, 4, 6, 7, 9,11, 12, 15, 20.
Write a program to determine the shortest growing rectangular spiral (in total length) that ends at a given integer point (x, y) in the fi rst quadrant or determine that there is no such spiral.

输入

The first line of input contains a single integer P, (1 ≤ P ≤ 1000), which is the number of data sets that follow. Each data set should be processed identically and independently.
Each data set consists of a single line of input consisting of three space separated decimal integers.
The first integer is the data set number. The next two integers are the x and y coordinates of the desired end point (1 ≤ x ≤ 10000, 1 ≤ y ≤ 10000).

输出

For each data set there is a single line of output. If there is no spiral solution, the line consists of the data set number, a single space and ‘NO PATH’ (without the quotes). If there is a solution, the line consists of the data set number, a single space, the number of segments in the solution, a single space,followed by the lengths of the segments in order, separated by single spaces. The input data will be chosen so that no path requires more than 22 segments.

样例输入

3
1 1 1
2 3 5
3 8 4

样例输出

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

【题解】

  问是否存在一条螺旋折线使得跑到(x,y)点,每一次转折都是严格递增的顺序。

  请输出存在的路径。如果没有则输出"NO PATH"

【规律】

  1、如果是(x,y)y>x明显是有一条两次转折到达的点。

  2、如果  y==x,是不存在这样的路径。

  3、如果是  x<y,其实是利用x,y的差值关系来构建出来6步达到的效果,具体看代码。

 #pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC optimize("O3")
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
#define pi acos(-1.0)
#define nl "\n"
#define pii pair<ll,ll>
#define ms(a,b) memset(a,b,sizeof(a))
#define FAST_IO ios::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL)
using namespace std;
typedef long long ll;
const int mod = ;
ll qpow(ll x, ll y){ll s=;while(y){if(y&)s=s*x%mod;x=x*x%mod;y>>=;}return s;}
//ll qpow(ll a, ll b){ll s=1;while(b>0){if(b%2==1)s=s*a;a=a*a;b=b>>1;}return s;}
inline int read(){int x=,f=;char ch=getchar();while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}while(ch>=''&&ch<='') x=x*+ch-'',ch=getchar();return x*f;} const int N = 1e5+; int main()
{
int _, cas, x, y;
for(scanf("%d",&_);_--;)
{
scanf("%d",&cas);
scanf("%d%d",&x,&y);
printf("%d ",cas);
if(x==y) puts("NO PATH");
else if(x<y){
printf("2 %d %d\n",x,y);
}
else{
if(y<) puts("NO PATH");
else{
printf("6 1 2 3 %d %d %d\n",x+-y+, x+, x+);
}
} } }

最新文章

  1. 玩转Redis之Window安装使用(干货)
  2. 使用配置文件定义ADO.NET 的连接字符串
  3. C++之路进阶——poj3461(Oulipo)
  4. SQL初级第二课
  5. 团队项目SCRUM项目6.0 7.0
  6. .net mysql 支持表情
  7. HDU 5615 Jam&#39;s math problem
  8. sublime text2 中文乱码的解决办法
  9. 【USACO 2.3.3】零数列
  10. 伯克利DB的一个BUG
  11. 如何使用fiddler进行android手机测试
  12. WPF DataGrid_SelectChanged获取单元内容
  13. ThreadPoolExecutor的一点理解
  14. asp.net webapi 多文件上传
  15. 支持虚拟化也开来虚拟化就是装不上HyperV的解决方法
  16. 1.建立exception包,编写TestException.java程序,主方法中有以下代码,确定其中可能出现的异常,进行捕获处理。
  17. Unity文档总结(2)-Understanding Automatic Memory Management
  18. openssh升级的坑爹之路
  19. Unable to start Ocelot because either a ReRoute or GlobalConfiguration
  20. java web spring 发送邮件

热门文章

  1. Egyptian Collegiate Programming Contest (ECPC 2015) C题 Connecting Graph
  2. Python语法 - 生成器
  3. 感知机算法及BP神经网络
  4. mysql数据库学习二
  5. gensim word2vec实践
  6. linux里面源码安装imagemagick库
  7. C之静态内存和动态内存
  8. 阶段5 3.微服务项目【学成在线】_day02 CMS前端开发_07-vuejs研究-vuejs基础-v-bind指令
  9. Jmeter之分布式部署测试
  10. 【ASP.NET Core学习】远程过程调用 - gRPC使用