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

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

See range

And ax and ay is a positive integer greater than 2, it is understood the number will not exceed 60, because at approximately 1e18 2 ^ 60, the number of figures than 2 ^ 60-2 ^ 59> 1e16, the title must be greater than t , meaning not calculated.

You can first of all find valuable point. After he had entered with all misunderstanding points xs, ys sort of difference, were dp, dp [i] points to the i maximum number of points collected, the idea has obvious errors, not linear, but regional , think carefully a distant point plus the distance around a lot as a point dp 1 will be error, the status is incorrect (process I do not know why there has been an error with the data labs, later to draw attention).

Since x [i] = (x [i-1]) * ax + bx, and can be seen as a linear function is increasing. Just start to enumerate a range of starting point and end point subtraction on it, empathy y are positive integers, maintain a ans.

But need to determine the starting point and end point xs, ys distance which is smaller choice of which, from the starting point and end point i- j is constant.

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<vector>
#include<map>
#include<algorithm>
#include<queue>
#define MAX_len 50100*4
using namespace std;
typedef long long ll;
struct A {
    ll x,y;
}a[110];
ll js(ll a,ll b,ll x,ll y)
{
    return abs(a-x)+abs(b-y);
}
main()
{
    ll x0,y0,ax,ay,bx,by;
    ll xs,ys,t;
    cin>>x0>>y0>>ax>>ay>>bx>>by;
    cin>>xs>>ys>>t;
    ll i,j;
    ll len;
    len=1;
    a[len].x=x0;
    a[len++].y=y0;
    while(1)
    {
        x0=ax*x0+bx;
        y0=ay*y0+by;
        if(x0-xs+y0-ys>t)
        break;
        a[len].x=x0;
        a[len++].y=y0;
    }
    ll ans=0;
    for(i=1;i<len;i++)
    {
        for(j=i;j<len;j++)
        {
            ll dis=min(js(xs,ys,a[i].x,a[i].y),js(xs,ys,a[j].x,a[j].y));
            dis+=js(a[i].x,a[i].y,a[j].x,a[j].y);
            if(dis<=t)
                ans=max(j-i+1,ans);
        }
    }
    printf("%I64d",ans);
    return 0;
}

 

Published 56 original articles · won praise 17 · views 2293

Guess you like

Origin blog.csdn.net/weixin_43958964/article/details/104071432