【规律】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 ...
随机推荐
- MySQL新特性文档型数据库
mongodb在文档型数据库这方面一直做的很好,也发展了很多年,MySQL作为一个比较大众的数据库也慢慢支持了该特性,下面介绍一下MySQL支持文档型数据库的简单操作. 环境: 主机名 IP 系统 软 ...
- Maven Web项目出现org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException错误
1. 问题描述 初学Maven,新建了一个基于Web骨架的Web项目,jar 包也导好了,作用域也设置正确了,Tomcat也正常运行了,可是就是说编译错误. 2. 问题原因 虽然我配置了Tomcat ...
- pwn学习日记Day6 基础知识积累
知识杂项 ELF:在计算机科学中,是一种用于二进制文件.可执行文件.目标代码.共享库和核心转储格式文件. char fgets(char buf, int bufsize, FILE stream); ...
- ArcGIS超级工具-征地部标准坐标导出导入 SPTOOLS
ArcGIS超级工具简称SPTOOLS 1.1征地部标准坐标导出 界面如下: 操作视频: https://weibo.com/tv/v/HvpNBrfeq?fid=1034:4374872936357 ...
- hive进阶 技巧
1.日期格式转换(将yyyymmdd转换为yyyy-mm-dd) select from_unixtime(unix_timestamp('20180905','yyyymmdd'),'yyyy-mm ...
- 属性 每秒10万吞吐 并发 架构 设计 58最核心的帖子中心服务IMC 类目服务 入口层是Java研发的,聚合层与检索层都是C语言研发的 电商系统里的SKU扩展服务
小结: 1. 海量异构数据的存储问题 如何将不同品类,异构的数据统一存储起来呢? (1)全品类通用属性统一存储: (2)单品类特有属性,品类类型与通用属性json来进行存储: 2. 入口层是Java研 ...
- android指纹识别认证实现
Android从6.0系统支持指纹认证功能 启动页面简单实现 package com.loaderman.samplecollect.zhiwen; import android.annotation ...
- 防止sshd服务被暴力破解
方法有很多种,这里介绍两种. (1).配置安全的shhd设置 不允许root用户直接登录到系统,添加一个普通用户,必要时再切换到root用户. 修改默认端口号. 不允许密码登录,只能通过密钥登录系统. ...
- BTE的一些知识
1.今天遇到一个问题,看项目上做了BTE增强00001120 事件的BTE 但是自定义函数 更改了参数 t_bseg t_bkpf MODIFY t_bkpf FROM ls_bkpf TRAN ...
- windows和Linux下定时启动或关闭服务
http://blog.csdn.net/clare504/article/details/17410643 1.Windows下的定时启动程序可以采用系统的计划和任务,定时启动服务可以在计划任务中添 ...