D. Aroma's Search----思维(难)

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 0-th node is (x0,y0)
For i>0, the coordinates of i-th node is (ax⋅xi−1+bx,ay⋅yi−1+by)
Initially Aroma stands at the point (xs,ys). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn’t need to return to the entry point (xs,ys) to warp home.

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

From the point (x,y), Aroma can move to one of the following points: (x−1,y), (x+1,y), (x,y−1) or (x,y+1). This action requires 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 x0, y0, ax, ay, bx, by (1≤x0,y0≤1016, 2≤ax,ay≤100, 0≤bx,by≤1016), which define the coordinates of the data nodes.

The second line contains integers xs, ys, t (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.

题意:给定x0,y0,ax,ay,bx,by,一堆数据节点:(x0,y0),(x1,y1) = (ax* x0+bx,ay*y0+by),起点(xs,ys),时间t,走一步都需要1单位时间,t时间内,从起点出发最多可以吃到多少个数据节点

解析:本题最重要的是 2<=ax,ay<=100,这个范围相当重要。通过这个范围我们可以知道数据节点很少,最多不超过(64=2^64 > 10^16)。因为通过公式,可以得知数据节点逐渐递增。
在一维平面内,假设x0=1,ax=2,bx=0,那么x1=2,x2=4,x3=8,x4=16,x5=32,x6=64.
我们观察x0,x1,x2,x3,x4,x5,x6。x4到x5的距离为16,但是x4到x0的距离为15
再比如x5到x6的距离为32,但是x5到x0的距离为31。发现往左走比往右走更优,由此我们可以贪心得出我们先向左边走,如果还有剩余我们再向右边走。



#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+1000;
ll x0[N],y0[N];
ll ax,ay,bx,by,sx,sy,t;
int tot;
int slove(int x)
{
	int ans=0;
	ll sxx=sx;
	ll syy=sy;
	ll st=0;
	for(int i=x;i>=0;i--) //往左走更优
	{
		st+=abs(sxx-x0[i])+abs(syy-y0[i]);
		if(st>t) break;
		ans++;
		sxx=x0[i];
		syy=y0[i];
	}
	if(st<=t) //剩余的,往右走
	{
		for(int i=x+1;i<=tot;i++)
		{
				st+=abs(sxx-x0[i])+abs(syy-y0[i]);
				if(st>t) break;
				ans++;
				sxx=x0[i];
				syy=y0[i];
		}
	}
	return ans;
}
int main()
{
	cin>>x0[0]>>y0[0]>>ax>>ay>>bx>>by;
	cin>>sx>>sy>>t;
	for(int i=1;;i++)
	{
		tot=i;
		x0[i]=x0[i-1]*ax+bx;
		y0[i]=y0[i-1]*ay+by;
		if(x0[i]>sx&&y0[i]>sy&&x0[i]+y0[i]-sx-sy>t) break; //因为数据节点是有限的,都大于t肯定不满足的。
	} 
	int ans=0; 
	for(int i=0;i<=tot;i++) ans=max(ans,slove(i));
	cout<<ans<<endl;
}
发布了309 篇原创文章 · 获赞 6 · 访问量 5267

猜你喜欢

转载自blog.csdn.net/qq_43690454/article/details/104073462