CF1293 D. Aroma's Search(构造)

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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值