【规律】Growing Rectangular Spiral
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.
输入
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).
输出
样例输入
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的更多相关文章
- URAL 1224. Spiral (规律)
1224. Spiral Time limit: 1.0 second Memory limit: 64 MB A brand new sapper robot is able to neutrali ...
- [LeetCode] Spiral Matrix 螺旋矩阵
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral or ...
- 【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 ...
- SCAU 10893 Spiral
10893 Spiral 时间限制:1000MS 内存限制:65535K 题型: 编程题 语言: 无限制 Description Given an odd number n, we can ar ...
- Gridland(规律)
Gridland Time Limit: 2 Seconds Memory Limit: 65536 KB BackgroundFor years, computer scientists ...
- [Solution] 885. Spiral Matrix Ⅲ
Difficulty: Medium Problem On a 2 dimensional grid with R rows and C columns, we start at (r0, c0) f ...
- [算法][LeetCode]Spiral Matrix
题目要求 Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spir ...
- PAT 1105 Spiral Matrix[模拟][螺旋矩阵][难]
1105 Spiral Matrix(25 分) This time your job is to fill a sequence of N positive integers into a spir ...
- [算法][LeetCode]Spiral Matrix——螺旋矩阵
题目要求 Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spir ...
随机推荐
- Robot Framework(十八) 支持工具
5支持工具 5.1库文档工具(libdoc) libdoc是一种用于为HTML和XML格式的测试库和资源文件生成关键字文档的工具.前一种格式适用于人类,后者适用于RIDE和其他工具.Libdoc也没有 ...
- nginx安装第三方模块echo-nginx-module
cd ~ wget -S https://github.com/agentzh/echo-nginx-module/archive/master.zip mv master echo-nginx-mo ...
- Singleton模式(单例模式) 饿汉式和懒汉式
目的:整个应用中有且只有一个实例,所有指向该类型实例的引用都指向这个实例. 好比一个国家就只有一个皇帝(XXX),此时每个人叫的“皇帝”都是指叫的XXX本人; 常见单例模式类型: 饿汉式单例:直接将对 ...
- 一个XP SP3调用0地址蓝屏BUG
0x00 蓝屏的堆栈 在XP SP3上跑POC之后,一段时间之后会出现蓝屏,蓝屏的堆栈如下,可以看出是ACKData里面CALL了一个0指针导致的蓝屏 0x01 蓝屏原因 1 ETW(Event Tr ...
- Qt for Android (二) Qt打开android的相册
以下有一个可以用的Demo https://files.cnblogs.com/files/wzxNote/Qt-Android-Gallery-master.zip 网盘地址: https://pa ...
- Flutter移动电商实战 --(16)切换后页面状态的保持AutomaticKeepAliveClientMixin
底栏切换每次都重新请求是一件非常恶心的事,flutter 中提供了AutomaticKeepAliveClientMixin 帮我们完成页面状态保存效果. 1.AutomaticKeepAliveCl ...
- 分布式系统的应用程序性能监视工具,专为微服务、云本机架构和基于容器(Docker、K8s、Mesos)架构而设计。 SkyWalking
Apache SkyWalking™ | SkyWalking Teamhttp://skywalking.apache.org/zh/ Application performance monitor ...
- 免费下载 SetupVPN CRX 3.7.0 for Chrome OR QQ浏览器
免费下载 SetupVPN CRX 3.7.0 for Chrome OR QQ浏览器 Lifetime Free VPN(微劈嗯) 下载setupvpn 3.7.0的crx文件, 打开chrome的 ...
- 【I·M·U_Ops】------Ⅱ------ IMU自动化运维平台之CMDB
说明本脚本仅作为学习使用,请勿用于任何商业用途.本文为原创,遵循CC 4.0 by-sa版权协议,转载请附上原文出处链接和本声明. #A 我理解的 CMDB CMDB翻译过来,Configuratio ...
- Hbase shell操作表
启动hbase shell ./bin/hbase shell 1.创建表,查看表 create 'tableName', 'familykey1','familykey2',.... eg. cre ...