Codeforces Round #614 (Div. 2) D. Aroma's Search

题目链接:http://codeforces.com/contest/1293/problem/D

题意:

给定x0,y0,ax,ay,bx,by

即一堆经验点:(x0,y0),(x1,y1)等价于(ax*x0+bx,ay*y0+by),(x2,y2)等价于(ax*x1+bx,ay*y1+by),(x3,y3)等价于(ax*x2+bx,ay*y2+by)......

再给定xs,ys,t

即起点(xs,ys),时间t

上下左右每走一步都需要1单位时间,问在t时间内,从起点出发最多可以吃到多少个经验包

思路:

因为经验点之间呈线性关系,且逐倍增加(ax和ay都是大于等于2,x0,y0,bx,by都是非负的)

容易想象,吃一段连续的经验包为最佳情况,假设要收集第i个经验包到第r个经验包,最佳路线是以下两种路线之一:

起点到第i个经验包,再到第r个经验包

起点到第r个经验包,再到第i个经验包

由于1e16不会超过53个点,所以暴力枚举到达的起点l和终点r即可。

英文题解:http://codeforces.com/blog/entry/73051

#include<bits/stdc++.h>
#define ll long long 
using namespace std;
const long long inf=1e16; 
pair<ll,ll> p[200];
int main()
{
    ll x0,y0,ax,ay,bx,by;
    ll xs,ys,t,tot=1;
    cin>>x0>>y0>>ax>>ay>>bx>>by;
    cin>>xs>>ys>>t;
    p[0]={x0,y0};
    for(int i=1;;i++)
    {
        ll nx=p[i-1].first*ax+bx;
        ll ny=p[i-1].second*ay+by;
        p[i]={nx,ny};
        tot++;
        if(nx>inf||ny>inf)break;
    }
    int ans=0;
    for(int i=0;i<tot;i++)
    {
        ll dis=abs(p[i].first-xs)+abs(p[i].second-ys);
        for(int j=0;j<tot;j++)
        {
            if(dis+abs(p[i].first-p[j].first)+abs(p[i].second-p[j].second)<=t)
            {
                ans=max(ans,1+abs(i-j));
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/myrtle/p/12216254.html