当前位置: 首页 > 工具软件 > Aroma > 使用案例 >

CF1293 D. Aroma's Search(构造)

井誉
2023-12-01

KIVΛ & Nikki Simmons - Perspectives
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 (푥0,푦0)
For 푖>0, the coordinates of 푖-th node is (푎푥⋅푥푖−1+푏푥,푎푦⋅푦푖−1+푏푦)
Initially Aroma stands at the point (푥푠,푦푠). She can stay in OS space for at most 푡 seconds, because after this time she has to warp back to the real world. She doesn’t need to return to the entry point (푥푠,푦푠) to warp home.

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

From the point (푥,푦), Aroma can move to one of the following points: (푥−1,푦), (푥+1,푦), (푥,푦−1) or (푥,푦+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 푡 seconds?

Input
The first line contains integers 푥0, 푦0, 푎푥, 푎푦, 푏푥, 푏푦 (1≤푥0,푦0≤1016, 2≤푎푥,푎푦≤100, 0≤푏푥,푏푦≤1016), which define the coordinates of the data nodes.

The second line contains integers 푥푠, 푦푠, 푡 (1≤푥푠,푦푠,푡≤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 푡 seconds.

Examples
inputCopy
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 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.

题意:
标记的格子为(xi,yi)
xi = xi-1 * ax + bx
yi = yi-1 * ay + by;
出发点为xs,ys。移动一格要一秒。求最多可以遍历几个标记的格子

思路:
观察数据范围可以得到,这样的标记格子最多50个(因为ax,ay ≥ 2)。
并且格子分布属于上凹函数。那么到了其中一个点后,一直向上或者一直向下肯定是最优的。

可以枚举最一开始到哪个点,然后看最多到几个点。

#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

typedef long long ll;

const ll maxn = 2e16;
struct Node
{
    ll x,y;
    ll s;
}nodes[105],xx;
ll xs,ys,t;

int cnt = 1;

ll dist(Node a,Node b)
{
    return abs(a.x - b.x) + abs(a.y - b.y);
}
ll solve1(int pos)
{
    ll s = xs + ys;
    ll ans1 = 0;
    ll tt = t;
    tt -= dist(nodes[pos],xx);
    if(tt >= 0)ans1++;
    for(int i = pos + 1;i <= cnt;i++)
    {
        tt -= dist(nodes[i],nodes[i - 1]);
        if(tt >= 0)ans1++;
        else break;
    }
    tt -= dist(nodes[cnt], nodes[pos]);
    for(int i = pos;i >= 2;i--)
    {
        tt -= dist(nodes[i], nodes[i - 1]);
        if(tt >= 0)ans1++;
        else break;
    }
    
    return ans1;
}

ll solve2(int pos)
{
    ll s = xs + ys;
    ll ans1 = 0;
    ll tt = t;
    tt -= dist(nodes[pos],xx);
    if(tt >= 0)ans1++;
    for(int i = pos - 1;i >= 1;i--)
    {
        tt -= dist(nodes[i + 1],nodes[i]);
        if(tt >= 0)ans1++;
        else break;
    }
    tt -= dist(nodes[1],nodes[pos]);
    for(int i = pos + 1;i <= cnt;i++)
    {
        tt -= dist(nodes[i], nodes[i - 1]);
        if(tt >= 0)ans1++;
        else break;
    }
    
    return ans1;
}

int main()
{
    ll x0,y0,ax,ay,bx,by;
    scanf("%lld%lld%lld%lld%lld%lld",&x0,&y0,&ax,&ay,&bx,&by);
    scanf("%lld%lld%lld",&xs,&ys,&t);
    nodes[1].x = x0;nodes[1].y = y0;nodes[1].s = x0 + y0;
    xx.x = xs;xx.y = ys;

    for(int i = 2;i <= 5;i++)
    {
        nodes[i].x = nodes[i - 1].x * ax + bx;
        nodes[i].y = nodes[i - 1].y * ay + by;
        if(dist(nodes[i],xx) > maxn)break;
        cnt++;
    }
    
    ll ans = 0;
    for(int i = 1;i <= cnt;i++)
    {
        ans = max(ans,max(solve1(i),solve2(i)));
    }
    printf("%lld\n",ans);
    return 0;
}

 类似资料: