Link: Aroma’s Search

D. Aroma's Search

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

The coordinates of the 0-th node is (x0,y0)
For i>0, the coordinates of i-th node is (ax⋅xi−1+bx,ay⋅yi−1+by)
Initially Aroma stands at the point (xs,ys). She can stay in OS space for at most 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 (xs,ys) to warp home.

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

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

Input
The first line contains integers x0, y0, ax, ay, bx, by (1≤x0,y0≤1e16, 2≤ax,ay≤100, 0≤bx,by≤1e16), which define the coordinates of the data nodes.

The second line contains integers xs, ys, t (1≤xs,ys,t≤1e16) – 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 seconds.

Examples
input
1 1 2 3 1 0
2 4 20
output
3
input
1 1 2 3 1 0
15 27 26
output
2
input
1 1 2 3 1 0
2 2 1
output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1,1), (3,3), (7,9), (15,27) and (31,81) (remember that nodes are numbered from 0).

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

Go to the coordinates (3,3) and collect the 1-st node. This takes |3−2|+|3−4|=2 seconds.
Go to the coordinates (1,1) and collect the 0-th node. This takes |1−3|+|1−3|=4 seconds.
Go to the coordinates (7,9) and collect the 2-nd node. This takes |7−1|+|9−1|=14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:

Collect the 3-rd node. This requires no seconds.
Go to the coordinates (7,9) and collect the 2-th node. This takes |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.

Problem solving:
这道题的意思就是在一个无限大的二维平面内。有一个人位于起点xs,ys。每秒可以走一格,相邻的格子。现在告诉你有一种格子中存在着金币(就看成是金币吧),问你这个人在规定的时间t内最多可以取到多少金币。

从一个位置走到另一个位置花费的时间其实就是横纵坐标差的绝对值之和。有金币的格子坐标没有给我们,只是给了一个递推式xi=ax⋅x(i−1)+bx,yi=ay⋅y(i−1)+by,我们知道,累乘是很大的,并且题目中说最大不会超过1e16,所以其实有金币的格子是很少的。并且我们还可以知道,当你选择了第一个取得金币之后,如果你还想保证在有限时间内取到的金币最多的话那么接下来取金币的顺序就定了,因为金币之间的距离是按比值增加的。因我们就可以暴力枚举第一次取得的金币的所有可能,然后每次更新最大值即可。

Code:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
ll        x[maxn], y[maxn];
int main()
{
    ll s, ax, ay, bx, by, xs, ys, t, ans = 0;
    cin >> x[0] >> y[0] >> ax >> ay >> bx >> by >> xs >> ys >> t;
    for (int i = 1;; i++)
    {
        x[i] = ax * x[i - 1] + bx;
        y[i] = ay * y[i - 1] + by;
        if (x[i] >= xs + t || y[i] >= ys + t)
        {
            s = i;
            break;
        }
    }
    for (int i = 0; i < s; i++)
    {
        for (int j = 0; j < s; j++)
        {
            ll d = abs(x[i] - xs) + abs(y[i] - ys) + abs(x[j] - x[i]) + abs(y[j] - y[i]);
            if (d <= t)
                ans = max(ans, abs(j - i) + (ll) 1);
        }
    }
    cout << ans << endl;
    return 0;
}

跟oi爷成功的一次py(希望FST善良一点)

少考虑一种情况WA了(果然FST不会善良)