B. Aroma's Search (Thinking + Greed + Violence)

https://codeforces.com/problemset/problem/1292/B


Ideas:

Consider that the smallest 2 times is also an exponential. So the answer is the last 100 points. And there is a greedy decision, giving priority to the one on the left.

Because it takes too much time to finish the string on the left and not the right of a complete interval.

2^1+2^2<2^3

Then there is a problem. For example, my starting point is very close to the interval on the right. At this time, I have to take the interval on the right before running to the left. How to deal with it.

The starting point of the violent enumeration is the current i-th one. If you can take the other and don't consider it along the way, you will be able to traverse to the answer state we want. Then run to the left, and then run to the right after running

 

#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=100;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL a[maxn],b[maxn],tot=0;
bool vis[maxn];
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  LL x0,y0,ax,ay,bx,by;cin>>x0>>y0>>ax>>ay>>bx>>by;
  LL xs,ys,t;cin>>xs>>ys>>t;
  tot++;
  a[tot]=x0;b[tot]=y0;
  while(tot<=70){
    ++tot;
    LL nx=ax*a[tot-1]+bx;
    LL ny=ay*b[tot-1]+by;
    a[tot]=nx;
    b[tot]=ny;
    if( nx>xs&&ny>ys&&abs(nx-xs)+abs(ny-ys)>t ) break;
  }
/*  debug(tot);
  for(LL i=1;i<=tot;i++){
    cout<<a[i]<<" "<<b[i]<<"\n";
  }*/
  LL ans=0;
  for(LL i=1;i<=tot;i++){///枚举人先拿i点的数据

     LL temp=t;LL res=0;
     if(abs(a[i]-xs)+abs(b[i]-ys)<=temp){
        res++;
        temp-=(abs(a[i]-xs)+abs(b[i]-ys));
     }
     else {ans=max(ans,res);continue;}

     for(LL j=i-1;j>=1;j--){///先从Pi--->P0方向拿
        if(abs(a[j]-a[j+1])+abs(b[j]-b[j+1])<=temp ){
           res++;
           temp-= ( abs(a[j]-a[j+1])+abs(b[j]-b[j+1]) );
        }
        else break;
     }
     for(LL j=1;j<=tot;j++){///从P0--->P∞方面拿
        if(abs(a[j+1]-a[j])+abs(b[j+1]-b[j])<=temp){

            temp-=( abs(a[j+1]-a[j])+abs(b[j+1]-b[j]) );
            if(j>=i) res++;
        }
        else break;
     }
     ans=max(ans,res);
  }
  cout<<ans<<"\n";
return 0;
}

 

Guess you like

Origin blog.csdn.net/zstuyyyyccccbbbb/article/details/114929966