【规律】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 ...
随机推荐
- mapreduce 倒序 排序 最简单 易上手
对于mapreduce倒序只需要建立一个类,然后继承WritableComparator 在重写 Compare函数最后在main里调用一下,就可以实现倒序排序: 代码: public static ...
- gitlab 配置.ssh实现免密登陆
首次配置gitlab的.ssh时 安装gitbash 通过gitbash 配置.ssh 打开gitbash,输入如下命令生成ssh,邮箱换成自己的 ssh-keygen -t rsa -C " ...
- java代理,手把手交你写java代理
一:常用的java代理模式 一般经常做java开发的知道java的代理模式一共有三种,第一种也就是静态代理,这种用法比较简单,没有什么魔法棒,比较好理解,另外两种分别是JDK代理和cglib代理,他们 ...
- [Oracle]察看一张表的约束 和 察看一张表的索引
--察看一张表的约束select table_name,constraint_name,constraint_type from user_constraints where table_name=u ...
- Mac 平台安装MySQL
Mac 平台安装MySQL 一.下载MySQL MySQL官网上https://dev.mysql.com/downloads/mysql/,下载Community Server版 出现如下界面, ...
- protected-broadcast 规范使用系统应用组件自定义广播
1. protected-broadcast 规范使用系统应用组件自定义广播 参考:https://blog.csdn.net/TaylorPotter/article/details/7019424 ...
- 设置Win10默认启动的Linux子系统版本,启动指定Linux发行版
设置Win10默认启动的Linux子系统版本,启动指定Linux发行版 MS酋长一年前已经与大家分享了启用“适用于Linux的Windows子系统(WSL)”的方法,但当时所能安装的只有由Cano ...
- Linux学习:Makefile简介及模板
一.基本概念介绍: Makefile 文件就是告诉make命令需要怎么样的去编译和链接程序. 编写Makefile的基本规则: 1.如果这个工程没有编译过,那么我们的所有C文件都要编译并被链接. 2. ...
- c++ Container print
template<typename Container>void PrintContents(const Container& con) { Container::const_it ...
- 10 Flutter仿京东商城项目 商品分类跳转到商品列表传值 商品列表页面布局
pages下面新建: ProductList.dart import 'package:flutter/material.dart'; import '../services/ScreenAdaper ...