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:
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:
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:
In the second example, the optimal route to collect 22 nodes is as follows:
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;
}