http://codeforces.com/contest/1293/problem/D

 

题意:

二维平面上有若干个点,第i个点的坐标(xi,yi)满足xi=x_i-1*ax+bx,yi=y_y-1*ay+by

已知 ax,bx,ay,by,x0,y0 以及初始位置(xs,ys)

每秒钟可以往上下左右走1个单位

问在t秒内最多可以走到多少个点

 

虽然数据很大,但点数不会很多

因为ax,ay 大于等于2,所以在t秒内能到的点不超过log2(t)个

这些点可以预处理出来

因为x,y的坐标都满足一个一次函数,所以走到的点一定是一个连续的区间,走的同方向的一段花费的时间可以直接用最后一个点的坐标减去第一个点的坐标

假设是[l,r],即走到了预处理出的第l个点到第r个点

若先去的第z个点,z∈[l,r]

令d(i,j)=|xi-xj|+|yi-yj|

那么花费的时间等于 d(s,z)+min{ d(l,z),d(r,z) } + d(l,r)

时间复杂度 log2(t)^3

 

优化:

z要么等于l,要么等于r

证明(以x坐标为例,y坐标同理):

 

若xs<=xl,则z=l

若xs>=xr,则z=r

若xl<xs<xr,所需时间为 d(s,z)+min{ d(l,z),d(r,z) } + d(l,r) ,而 d(s,z)+min{ d(l,z),d(r,z) } = min{ d(l,s),d(r,s)} ,所以所需时间为 min{ d(l,s),d(r,s)} + d(l,r)

时间复杂度 log2(t)^2

 

#include<vector>
#include<iostream>
#include<algorithm>

using namespace std;

typedef long long LL; 
typedef pair<LL,LL> pr;

vector<pr>v;

int main()
{
    LL x0,y0,ax,ay,bx,by,xs,ys,t;
    cin>>x0>>y0>>ax>>ay>>bx>>by>>xs>>ys>>t;
    v.push_back(pr(x0,y0));
    while(1)
    {
        x0=x0*ax+bx;
        y0=y0*ay+by;
        if(x0-xs+y0-ys<=t) v.push_back(pr(x0,y0));
        else break; 
    }
    int n=v.size(),ans=0;
    LL len1,len2;
    for(int i=0;i<n;++i)
    {
        len1=abs(v[i].first-xs)+abs(v[i].second-ys);
        for(int j=i;j<n;++j)
        {
            len2=abs(v[j].first-xs)+abs(v[j].second-ys);
            if(min(len1,len2)+v[j].first-v[i].first+v[j].second-v[i].second<=t) ans=max(ans,j-i+1);
            else break;
        }
    }
    cout<<ans;
    return 0;
}

 

D. Aroma's Search
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 (x0,y0)
  • For (ax⋅xi−1+bx,ay⋅yi−1+by)

Initially Aroma stands at the point (xs,ys) to warp home.

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

  • From the point 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 0≤bx,by≤1016 ), which define the coordinates of the data nodes.

The second line contains integers 1≤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 t seconds.

Examples
Input
Copy
1 1 2 3 1 0
2 4 20
Output
Copy
3
Input
Copy
1 1 2 3 1 0
15 27 26
Output
Copy
2
Input
Copy
1 1 2 3 1 0
2 2 1
Output
Copy
0
Note

In all three examples, the coordinates of the first 0 ).

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

  • Go to the coordinates |3−2|+|3−4|=2 seconds.
  • Go to the coordinates |1−3|+|1−3|=4 seconds.
  • Go to the coordinates |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 |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.

相关文章:

  • 2021-12-22
  • 2021-09-30
  • 2021-05-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-22
  • 2022-12-23
  • 2022-12-23
  • 2021-05-20
  • 2021-12-11
  • 2022-01-16
  • 2022-03-08
相关资源
相似解决方案