CF1292B Aroma's Search(贪心+枚举)

传送门

思路

点的排列是开始密集,越来越稀疏。
贪心的考虑,先去密集的地方取数据点更优。
如果取完了密集地方的数据点,也还是要取稀疏的地方取。
由于实际在时间\(t\)范围内可达的点大约只有70个,可以枚举这些点作为中间点。
第一步:从起点到达中间点;
第二步:从中间点往密集的地方走,即下标小的地方;
第三步:走到下标为\(0\)的点后再往上走,记录未走过的数据点个数,直到不能走为止。

代码


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include<map>
#include<set>
#include<vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll>PLL;
typedef pair<int, int>PII;
typedef pair<double, double>PDD;
#define I_int ll
inline ll read()
{
    ll x = 0, f = 1;
    char ch = getchar();
    while(ch < '0' || ch > '9')
    {
        if(ch == '-')f = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9')
    {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}
#define read read()
#define closeSync ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define multiCase int T;cin>>T;for(int t=1;t<=T;t++)
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define repp(i,a,b) for(int i=(a);i<(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define perr(i,a,b) for(int i=(a);i>(b);i--)
ll ksm(ll a, ll b, ll p)
{
    ll res = 1;
    while(b)
    {
        if(b & 1)res = res * a % p;
        a = a * a % p;
        b >>= 1;
    }
    return res;
}
const int inf = 0x3f3f3f3f;
#define PI acos(-1)
const int maxn=1e5+10;

PLL pos[maxn];
ll ax,bx,ay,by,sx,sy,t;

ll cul(PLL a,PLL b){
    return abs(a.first-b.first)+abs(a.second-b.second);
}

int main()
{
    cin>>pos[0].first>>pos[0].second>>ax>>ay>>bx>>by;
    cin>>sx>>sy>>t;
    PLL s;
    s.first=sx;s.second=sy;
    int n=0;
    while(++n){
        pos[n].first=ax*pos[n-1].first+bx;
        pos[n].second=ay*pos[n-1].second+by;
        if(pos[n].first>sx&&pos[n].second>sy&&cul(s,pos[n])>t){
            break;
        }
    }

    ll res=0;
    for(int i=0;i<=n;i++){
        ll ans=0,tmp=t;
        if(cul(s,pos[i])>t){
            continue;
        }
        else{
            tmp-=cul(s,pos[i]);
            ans++;
            for(int j=i;j;j--){
                if(cul(pos[j],pos[j-1])<=tmp){
                    tmp-=cul(pos[j],pos[j-1]);
                    ans++;
                }
                else break;
            }
            for(int j=1;j<=n;j++){
                if(cul(pos[j],pos[j-1])<=tmp){
                    tmp-=cul(pos[j],pos[j-1]);
                    if(j>i) ans++;
                }
                else break;
            }
        }
        res=max(res,ans);
    }

    printf("%lld\n",res);
    return 0;
}

/*

**/





posted @ 2021-06-01 17:45  OvO1  阅读(73)  评论(0编辑  收藏  举报