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. UVALive 3716 DNA Regions ——(扫描法)

    乍一看这个问题似乎是很复杂,但其实很好解决. 先处理出每个点到原点的距离和到x正半轴的角度(从x正半轴逆时针旋转的角度).然后以后者进行排序. 枚举每一个点到圆心的距离,作为半径,并找出其他到圆心距离 ...

  2. ICEM—非结构化周期网格

    原视频下载地址:https://yunpan.cn/cPBnmsNheJ46q  访问密码 3441

  3. java设计模式简述

    1.代理模式:有一个接口或者顶层类(可以是抽象的)A,一个实现类B,一个代理类C,代理类C之所以能够是代理类,是因为1.C也实现了A.2.C持有A的依赖,用来注入真实的实现B.3.C的实现方法中实际调 ...

  4. Sql中truncate,delete以及drop的比较

    相同点: 1.truncate和不带where子句的delete.以及drop都会删除表内的数据. 2.drop.truncate都是DDL语句(数据定义语言),执行后会自动提交. 不同点: 1. t ...

  5. 图解centos7如何关闭ipv6仅使用ipv4

    方法/步骤     使用ifconfig命令查看网卡信息,如果出现inet6 fe80::20c:29ff:fed0:3514,说明机器开启了ipv6,如下图所示:   编辑/etc/sysctl.c ...

  6. mongodb 添加用户报错TypeError:db.addUser is not a function (mongodb3.4.1)

    1:问题如下: 原因是 新版的MongoDB已经不支持addUser方法了. 改成createUser了. 使用方法如下    2:具体解释一下db.createUser()方法的用法   定义: 创 ...

  7. JAVA 基础编程练习题21 【程序 21 求阶乘】

    21 [程序 21 求阶乘] 题目:求 1+2!+3!+...+20!的和 程序分析:此程序只是把累加变成了累乘. package cskaoyan; public class cskaoyan21 ...

  8. Spring Boot自定义Mapper的SQL语句

    代码如下: 先创建一个Provider类: public class RptEbankFsymtTranflowingProvider { public String select(String or ...

  9. iOS-在AFN基础上进行网络请求的封装

    网络请求的思路:如果请求成功的话AFN的responseObject就是解析好的. 1发送网络请求:get/post/或者别的 带上URL,需要传的参数 2判断后台网络状态码有没有请求成功: 3 请求 ...

  10. 局域网中win10作为服务器,其他机器无法连接怎么办

    内网中某台win10服务器装了一个mysql,其他机器无法连接,通常是防火墙的原因. 下面就讲解一下win10服务器中如何配置入站防火墙. 场景:win10 机器上安装了一个mysql数据库,我的ma ...