Codeforces Round 614 (Div. 1) B. Aroma‘s Search

Aroma’s Search

time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.

The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0 0 0, with their coordinates defined as follows:

  • The coordinates of the 0 0 0-th node is ( x 0 , y 0 ) (x_0, y_0) (x0,y0)
  • For i > 0 i > 0 i>0, the coordinates of i i i-th node is ( a x ⋅ x i − 1 + b x , a y ⋅ y i − 1 + b y ) (a_x \cdot x_{i-1} + b_x, a_y \cdot y_{i-1} + b_y) (axxi1+bx,ayyi1+by)

Initially Aroma stands at the point ( x s , y s ) (x_s, y_s) (xs,ys). She can stay in OS space for at most t t t seconds, because after this time she has to warp back to the real world. She doesn’t need to return to the entry point ( x s , y s ) (x_s, y_s) (xs,ys) to warp home.

While within the OS space, Aroma can do the following actions:

  • From the point ( x , y ) (x, y) (x,y), Aroma can move to one of the following points: ( x − 1 , y ) (x-1, y) (x1,y), ( x + 1 , y ) (x+1, y) (x+1,y), ( x , y − 1 ) (x, y-1) (x,y1) or ( x , y + 1 ) (x, y+1) (x,y+1). This action requires 1 1 1 second.
  • If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 0 0 seconds. Of course, each data node can be collected at most once.

Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t t t seconds?

Input

The first line contains integers x 0 x_0 x0, y 0 y_0 y0, a x a_x ax, a y a_y ay, b x b_x bx, b y b_y by ( 1 ≤ x 0 , y 0 ≤ 1 0 16 1 \leq x_0, y_0 \leq 10^{16} 1x0,y01016, 2 ≤ a x , a y ≤ 100 2 \leq a_x, a_y \leq 100 2ax,ay100, 0 ≤ b x , b y ≤ 1 0 16 0 \leq b_x, b_y \leq 10^{16} 0bx,by1016), which define the coordinates of the data nodes.

The second line contains integers x s x_s xs, y s y_s ys, t t t ( 1 ≤ x s , y s , t ≤ 1 0 16 1 \leq x_s, y_s, t \leq 10^{16} 1xs,ys,t1016) – the initial Aroma’s coordinates and the amount of time available.

Output

Print a single integer — the maximum number of data nodes Aroma can collect within t t t seconds.

Example

i n p u t \tt input input
1 1 2 3 1 0
2 4 20
o u t p u t \tt output output
3
i n p u t \tt input input
1 1 2 3 1 0
15 27 26
o u t p u t \tt output output
2
i n p u t \tt input input
1 1 2 3 1 0
2 2 1
o u t p u t \tt output output
0

Note

In all three examples, the coordinates of the first 5 5 5 data nodes are ( 1 , 1 ) (1, 1) (1,1), ( 3 , 3 ) (3, 3) (3,3), ( 7 , 9 ) (7, 9) (7,9), ( 15 , 27 ) (15, 27) (15,27) and ( 31 , 81 ) (31, 81) (31,81) (remember that nodes are numbered from 0 0 0).

In the first example, the optimal route to collect 3 3 3 nodes is as follows:

  • Go to the coordinates ( 3 , 3 ) (3, 3) (3,3) and collect the 1 1 1-st node. This takes ∣ 3 − 2 ∣ + ∣ 3 − 4 ∣ = 2 |3 - 2| + |3 - 4| = 2 ∣32∣+∣34∣=2 seconds.
  • Go to the coordinates ( 1 , 1 ) (1, 1) (1,1) and collect the 0 0 0-th node. This takes ∣ 1 − 3 ∣ + ∣ 1 − 3 ∣ = 4 |1 - 3| + |1 - 3| = 4 ∣13∣+∣13∣=4 seconds.
  • Go to the coordinates ( 7 , 9 ) (7, 9) (7,9) and collect the 2 2 2-nd node. This takes ∣ 7 − 1 ∣ + ∣ 9 − 1 ∣ = 14 |7 - 1| + |9 - 1| = 14 ∣71∣+∣91∣=14 seconds.

In the second example, the optimal route to collect 2 2 2 nodes is as follows:

  • Collect the 3 3 3-rd node. This requires no seconds.
  • Go to the coordinates ( 7 , 9 ) (7, 9) (7,9) and collect the 2 2 2-th node. This takes ∣ 15 − 7 ∣ + ∣ 27 − 9 ∣ = 26 |15 - 7| + |27 - 9| = 26 ∣157∣+∣279∣=26 seconds.

In the third example, Aroma can’t collect any nodes. She should have taken proper rest instead of rushing into the OS space like that.

Tutorial

可以根据 x 0 x_0 x0, y 0 y_0 y0, a x a_x ax, a y a_y ay, b x b_x bx, b y b_y by,将所有坐标绝对值小于 3 × 1 0 16 3 \times 10 ^ {16} 3×1016 的点全找出来,最多有 log ⁡ 2 ( 3 × 1 0 16 ) \log_2 (3 \times 10 ^{16}) log2(3×1016) 个点

根据题意易得,如果将所有点依次连接起来,是一条具有递增趋势的折线,设 d ( i , j ) d(i, j) d(i,j) i i i 节点和 j j j 节点的距离,对于所有的 1 ≤ u < v < w 1 \leq u < v < w 1u<v<w,有 d ( u , v ) + d ( v , w ) = d ( u , w ) d(u, v) + d(v, w) = d(u, w) d(u,v)+d(v,w)=d(u,w)

可以用三层循环,其中一个点为切入此折线的点,在该点左侧和右侧各找一个点,如果可以将这两个点范围内的点都跑完则更新距离,以此方法进行三层循环暴力找点

此解法时间复杂度为 O ( log ⁡ 3 ( 3 × 1 0 16 ) ) \mathcal O(\log ^ 3 (3 \times 10 ^{16})) O(log3(3×1016)) 100 m s 100\ ms 100 ms 内可以跑完

Solution

x0, y0, ax, ay, bx, by = map(int, input().split())
xs, ys, t = map(int, input().split())
points = [[x0, y0]]
while points[-1][0] <= 3 * 10 ** 16 and points[-1][1] <= 3 * 10 ** 16:points.append([points[-1][0] * ax + bx, points[-1][1] * ay + by])ans = 0
for i, [in_x, in_y] in enumerate(points):now = t - abs(in_x - xs) - abs(in_y - ys)for j, [left_x, left_y] in enumerate(points[: i + 1]):for k, [right_x, right_y] in enumerate(points[i:]):if now - (right_x - left_x + right_y - left_y) - min((in_x - left_x + in_y - left_y), (right_x - in_x + right_y - in_y)) >= 0:ans = max(ans, k + (i - j) + 1)
print(ans)

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/web/26208.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

人工智能在肿瘤细胞分类中的应用|顶刊速递·24-06-06

小罗碎碎念 推文主题——人工智能在肿瘤细胞分类中的应用。 重点关注 临床方向的同学/老师建议重点关注第四篇&第六篇文章&#xff0c;最近DNA甲基化和蛋白组学与AI的结合&#xff0c;在顶刊中出现的频率很高&#xff0c;建议思考一下能否和自己的课题结合。 工科的同学重…

LeetCode题练习与总结:验证回文串--125

一、题目描述 如果在将所有大写字符转换为小写字符、并移除所有非字母数字字符之后&#xff0c;短语正着读和反着读都一样。则可以认为该短语是一个 回文串 。 字母和数字都属于字母数字字符。 给你一个字符串 s&#xff0c;如果它是 回文串 &#xff0c;返回 true &#xf…

入职一周感慨

上周太忙了&#xff0c;去打了个球&#xff0c;买了个二手电动车&#xff0c;然后按了个spa。所以忘记吾日三省吾身了&#xff0c;罪孽呀。 本来事情都很顺利的&#xff0c;昨天在工作上&#xff0c;我不小心把cdh集群的主节点ntp remove了&#xff0c;然后重启了所有服务&…

【永久使用】Xshell7+Xftp7免费版安装教程

Xshell7是用来连接linux服务器的软件。 Xftp7是和linux服务器进行文件操作的软件&#xff08;可新增&#xff0c;删除服务器上的文件&#xff09;&#xff0c;可嵌入在Xshell7中运行。 如何安装 先下载安装文件&#xff08;免费获取&#xff09; https://gitee.com/hadluo/…

网格重构技术在AI绘画中的革新作用

引言&#xff1a; 随着人工智能&#xff08;AI&#xff09;技术的飞速发展&#xff0c;艺术创作也迎来了前所未有的变革。AI绘画不仅改变了艺术家的创作方式&#xff0c;还为非专业人士开启了艺术创作的大门。在众多AI技术中&#xff0c;网格重构技术因其独特的作用和效果成为A…

JS实现文字溢出隐藏效果

需求场景 由于项目原因&#xff0c;经常需要使用到canvas来将dom生成为图片供用户保存&#xff0c;但canvas的css属性&#xff08;例如本文实现的文字溢出隐藏效果&#xff09;支持并不全面&#xff0c;所有有些功能只能用JS来实现了 实现思路 用JS循环判断填充文本后的元素…

为什么选择Symfony框架?深入解析PHP框架

目录 1. Symfony框架概述 1.1 什么是Symfony? 1.2 Symfony的历史 2. Symfony的核心特性 2.1 MVC架构 2.2 可重用的组件 2.3 Bundle系统 2.4 高度可配置性 2.5 强大的调试工具 3. 为什么选择Symfony框架? 3.1 性能与可扩展性 3.2 企业级应用的首选 3.3 活跃的社区…

Python NumPy 库详解

大家好&#xff0c;在当今数据驱动的世界中&#xff0c;处理大规模数据、进行复杂数值计算是科学研究、工程设计以及数据分析的关键任务之一。在Python生态系统中&#xff0c;NumPy&#xff08;Numerical Python&#xff09;库是一款备受推崇的工具&#xff0c;它为我们提供了高…

PHP调用快递地址解析接口助力项目优化

快递地址智能解析是日常开发中一个重要的工具&#xff0c;可以帮助快递公司提高效率&#xff0c;减少错误&#xff0c;进行数据分析。也可以帮助网购用户快速输入收货地址&#xff0c;提升用户体验。 看完以下操作文档&#xff0c;可以让你在开发中以最快时间完成这个功能&…

mybatis 之 DatabaseIdProvider 教程

mybatis之DatabaseIdProvider 应用中可能同时涉及到多个数据库&#xff0c;比如MySQL&#xff0c;oracle等等&#xff0c;那么当我们使用mybatis的时候&#xff0c;怎么做到动态切换呢&#xff1f;DatabaseIdProvider 可以帮助我们 public interface DatabaseIdProvider {def…

取消el-time-picker组件在Sarari浏览器中下拉回弹效果

在项目中用到el-time-picker组件来选择时间&#xff0c; 但是在Safari浏览器中&#xff0c;滑动分钟列表时&#xff0c;会取消时钟的选择&#xff0c;这是因为滑动分钟列表时有一个回弹效果&#xff0c;回弹把时钟的选择给取消掉了&#xff0c;我们现在要做的就是取消滑动时钟时…

谷歌配置邮箱stmp开发

谷歌的stmp开发&#xff0c;需要一个专用密码 首先要打开二部验证 然后再通过这个链接&#xff0c;创建专用密码 https://myaccount.google.com/u/6/apppasswords?gar1 然后拿专用密码去写在代码上&#xff0c;谷歌发邮件&#xff0c;不知道是不是国内还是什么原因&#xff…

Java-开发技巧

1.判断list或者map 用org.apache.commons.collections4包下的 CollectionUtils.isNotEmpty 2.判断字符串 用org.apache.commons.lang3包下的 StringUtils 3.执行分组操作&#xff0c;List<StatusDAO>不会为null情况 Map<LocalDateTime,List<StatusDAO>> …

Centos上部署Node服务和MongoDB

文章目录 1.Centos上安装运行Node服务1. 安装Node.js2.验证Node.js安装3.运行Node.js应用程序4.调试Node.js应用 2.Centos上安装MongoDB3.创建Node服务1.配置初始化文件2.创建index.js文件3.启动服务3.配置公网访问forever的引入pm2的引入 4.应对CORS跨域使用cors中间件手动设置…

深入理解MySQL分区技术

前言&#xff1a; 在数据量不断增长的当今时代&#xff0c;数据库的性能优化变得尤为重要。MySQL作为一款广泛使用的数据库管理系统&#xff0c;提供了多种性能优化手段&#xff0c;其中分区技术是提升大型表处理效率的有效方法之一。通过将数据分散到多个独立的物理子表中&am…

《大道平渊》· 拾叁 —— 失眠?忍不住乱想?不如反其道而行之!

《平渊》 拾叁 "睡觉的时候就是要胡思乱想" 声明&#xff1a;以下内容针对非失眠症人群&#xff0c;如果失眠不是偶尔发生&#xff0c;而是长期存在&#xff0c;以下内容和你无关&#xff0c;请尽早治疗&#xff0c;遵循医嘱。 失眠的本质是什么&#xff1f;心理因素…

C++并发之锁(std::lock_guard,std::unique_lock)

目录 1 概述2 使用实例3 接口使用3.1 lock_guard3.2 adopt_lock3.3 defer_lock3.4 try_to_lock3.5 try_lock3.6 release3.7 lock3.8 call_one1 概述 锁保护是通过使互斥对象始终处于锁定状态来管理互斥对象的对象。。   在构造时,互斥对象被调用线程锁定,在析构时,互斥被解…

Qt实现信号与槽,模拟Qt的信号与槽,观察者模式

运行在VS2022&#xff0c;x86&#xff0c;Debug下 33. Qt信号与槽 实现原理&#xff1a;观察者模式&#xff0c;即当一个对象被修改时&#xff0c;就会自动通知依赖它的对象。应用&#xff1a;对象间的通信。 33.1. Qt实现信号与槽&#xff0c;代码如下。 #include <QOb…

电脑撤回的快捷键是什么?

下面给大家介绍了各种办公应用的撤回以及反向撤回快捷键介绍&#xff0c;在ps、excel中都是可以使用的。 撤回键是ctrl加什么 1、撤销的快捷键是“CtrlZ”&#xff0c;用于取消上一步操作&#xff0c;对与在电脑系统上或软件内的操作均适用。重复按下可以取消多步操作。 2、而…

乡村振兴的法治保障:加强农村法治建设,完善乡村治理体系,提高农民法治素养,为美丽乡村建设提供有力保障

目录 一、引言 二、加强农村法治建设的必要性 &#xff08;一&#xff09;法治是乡村振兴的基石 &#xff08;二&#xff09;法治是乡村治理的保障 &#xff08;三&#xff09;法治是农民权益的守护者 三、完善乡村治理体系的路径 &#xff08;一&#xff09;加强乡村基…