Aroma‘s Search

https://codeforces.com/problemset/problem/1292/B

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 00, with their coordinates defined as follows:

  • The coordinates of the 00-th node is (x0,y0)(x0,y0)
  • For i>0i>0, the coordinates of ii-th node is (ax⋅xi−1+bx,ay⋅yi−1+by)(ax⋅xi−1+bx,ay⋅yi−1+by)

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

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

  • From the point (x,y)(x,y), Aroma can move to one of the following points: (x−1,y)(x−1,y), (x+1,y)(x+1,y), (x,y−1)(x,y−1) or (x,y+1)(x,y+1). This action requires 11 second.
  • If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 00 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 tt seconds?Input

The first line contains integers x0x0, y0y0, axax, ayay, bxbx, byby (1≤x0,y0≤10161≤x0,y0≤1016, 2≤ax,ay≤1002≤ax,ay≤100, 0≤bx,by≤10160≤bx,by≤1016), which define the coordinates of the data nodes.

The second line contains integers xsxs, ysys, tt (1≤xs,ys,t≤10161≤xs,ys,t≤1016) – 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 tt seconds.ExamplesinputCopy

1 1 2 3 1 0
2 4 20

outputCopy

3

inputCopy

1 1 2 3 1 0
15 27 26

outputCopy

2

inputCopy

1 1 2 3 1 0
2 2 1

outputCopy

0

Note

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

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

  • Go to the coordinates (3,3)(3,3) and collect the 11-st node. This takes |3−2|+|3−4|=2|3−2|+|3−4|=2 seconds.
  • Go to the coordinates (1,1)(1,1) and collect the 00-th node. This takes |1−3|+|1−3|=4|1−3|+|1−3|=4 seconds.
  • Go to the coordinates (7,9)(7,9) and collect the 22-nd node. This takes |7−1|+|9−1|=14|7−1|+|9−1|=14 seconds.

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

  • Collect the 33-rd node. This requires no seconds.
  • Go to the coordinates (7,9)(7,9) and collect the 22-th node. This takes |15−7|+|27−9|=26|15−7|+|27−9|=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.


思路:看到题目暴力的tag内心是懵逼的。后来知道了实际上不会超过60+点。因为取极限状态最小值是2的倍数。2^64也超过了题目的数据范围。从而可以暴力

同时要知道一个曼哈顿距离的小结论:

设d(i,j)表示点i到j的曼哈顿距离,可推出一个重要结论: d(i,i+1)+d(i+1,i+2)=d(i,i+2)

那么通过这个公式我们可以直接枚举左端点和右端点,这样就能直接获得经过这段区间的距离。

那么这样需要的时间是time=min(起点到左端点,起点到右端点)+d(左端点,右端点)

如果时间time<=t则可行,更新ans为max(ans,区间长度)

#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=105;
typedef long long LL;
LL x[maxn],y[maxn];
LL cnt=0;
LL dis(LL a,LL b,LL c,LL d)
{
	return fabs(a-c)+fabs(b-d);	
} 
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  LL ax,ay,bx,by,sx,sy,t;
  cin>>x[0]>>y[0]>>ax>>ay>>bx>>by;
  cin>>sx>>sy>>t;
  while(x[cnt]-sx<=t&&y[cnt]-sy<=t)
  {
  		cnt++;
  	    x[cnt]=ax*x[cnt-1]+bx;
  	    y[cnt]=ay*y[cnt-1]+by;
  }
  LL ans=0;
  for(LL i=0;i<=cnt;i++)
  	for(LL j=i;j<=cnt;j++)
  	{
  		LL temp=min(dis(sx,sy,x[i],y[i]),dis(sx,sy,x[j],y[j]));
		temp+=dis(x[i],y[i],x[j],y[j]);
		if(temp<=t) ans=max(ans,j-i+1);	
	}
	cout<<ans<<endl;
return 0;
}
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值