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

【规律】Growing Rectangular Spiral的更多相关文章

  1. URAL 1224. Spiral (规律)

    1224. Spiral Time limit: 1.0 second Memory limit: 64 MB A brand new sapper robot is able to neutrali ...

  2. [LeetCode] Spiral Matrix 螺旋矩阵

    Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral or ...

  3. 【leetcode】Spiral Matrix(middle)

    Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral or ...

  4. SCAU 10893 Spiral

    10893 Spiral 时间限制:1000MS  内存限制:65535K 题型: 编程题   语言: 无限制 Description Given an odd number n, we can ar ...

  5. Gridland(规律)

    Gridland Time Limit: 2 Seconds      Memory Limit: 65536 KB BackgroundFor years, computer scientists ...

  6. [Solution] 885. Spiral Matrix Ⅲ

    Difficulty: Medium Problem On a 2 dimensional grid with R rows and C columns, we start at (r0, c0) f ...

  7. [算法][LeetCode]Spiral Matrix

    题目要求 Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spir ...

  8. PAT 1105 Spiral Matrix[模拟][螺旋矩阵][难]

    1105 Spiral Matrix(25 分) This time your job is to fill a sequence of N positive integers into a spir ...

  9. [算法][LeetCode]Spiral Matrix——螺旋矩阵

    题目要求 Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spir ...

随机推荐

  1. fsLayui数据表格使用

    fsLayui 是一个基于layui的快速开发插件,支持数据表格增删改查操作,提供通用的组件,通过配置html实现数据请求,减少前端js重复开发的工作. GitHub下载 码云下载 测试环境地址:ht ...

  2. brew 切换国内的源

    切换到国内源 # 替换brew.git: cd "$(brew --repo)" # 中国科大: git remote set-url origin https://mirrors ...

  3. arcgis python 标注

    import arcpy mxd = arcpy.mapping.MapDocument("current") lyr = arcpy.mapping.ListLayers(mxd ...

  4. produceTestDate

    set serveroutput on --使用基本变量类型 declare --定义基本变量:类型 --基本数据类型 pnumber , ); pname ); pdate date; begin ...

  5. 下了个pkg包的jenkins,的使用方法

    三.如何启动Jenkins1.最简单的方法是双击Jenkins的pkg包,一步一步点同意,默认8080端口2.使用命令行启动打开terminal,进入到war包所在目录,执行命令: java -jar ...

  6. jemter 90%line的解释

    假如: 有10个数: 1.2.3.4.5.6.7.8.9.10    按由大到小将其排列. 求它的第90%百分位,也就是第9个数刚好是9 ,那么他的90%Line 就是9 . 另一组数: 2.2.1. ...

  7. 解析Python编程中的包结构

    解析Python编程中的包结构 假设你想设计一个模块集(也就是一个"包")来统一处理声音文件和声音数据.通常由它们的扩展有不同的声音格式,例如:WAV,AIFF,AU),所以你可能 ...

  8. JAVA 基础编程练习题18 【程序 18 乒乓球赛】

    18 [程序 18 乒乓球赛] 题目:两个乒乓球队进行比赛,各出三人.甲队为 a,b,c 三人,乙队为 x,y,z 三人.已抽签决定比赛名单. 有人向队员打听比赛的名单.a 说他不和 x 比,c 说他 ...

  9. fatal error: nvcuvid.h: No such file

    https://www.cnblogs.com/rabbull/p/11154997.html

  10. ABC技术落地_成功带动lot物联网行业、金融科技行业、智能人才教育。

    ABC技术:AI:Python神经网络和自然语言处理(NLP):C ++ 机器学习和神经网络:Java自然语言处理.搜索算法.神经网络:Lisp归纳逻辑项目和机器学习.Big Date:R.Pytho ...