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:
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:
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?
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.
Print a single integer — the maximum number of data nodes Aroma can collect within t seconds.
1 1 2 3 1 0
2 4 20
3
有很多个点特殊点,第一个特殊点坐标为(x0,y0),第 i 个特殊点坐标为 (ax⋅xi−1+bx , ay⋅yi−1+by)。一个人初始在(xs, ys),每一秒,他能向上下左右其中一个方向移动一步。求 t 秒内他最多能到达多少个特殊点。
输入中有个很重要的条件,2≤ax,ay≤100。ax , ay,都是大于等于2的,因为点的坐标都是正的,所以下一个点的横坐标至少是上一点的二倍(纵坐标也一样),指数级的增长。而到了后面点的坐标都大于很大了,而初始点的坐标范围,以及时间 t 的范围都是小于等于1016的,所以那些坐标很大的点实际上是到不了的。所以我们只需要关心坐标范围小于等于2*1016的特殊点。前面说了横纵坐标都是指数级的增长,1016其实也就不到100个点而已。所以求出所有合理的点,然后暴力求 t 时间内最多能到达的特殊点的数量即可。
对于这些点,一定是先从起始位置走到某个特殊点,然后依次访问这个特殊点左边或右边的点,知道时间超出 t,所以可以每局第一个走到特殊点,然后分别向左、向右暴力求能到达多少个特殊点,取最大即可。
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<ctype.h>
#include<cstring>
#include<vector>
#include<deque>
#include<map>
#include<iostream>
#include<iterator>
#define dbg(x) cout<<#x<<" = "<<x<<endl;
#define INF 0x3f3f3f3f
#define eps 1e-8
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
const int maxn = 300100;
const int mod = 1000000007;
struct node{
LL x, y;
}p[maxn], q;
LL dis(node a, node b);
int main()
{
int top=1, i, j, k, ans = 0;
LL ax, ay, bx, by, t;
scanf("%I64d %I64d %I64d %I64d %I64d %I64d", &p[0].x, &p[0].y, &ax, &ay, &bx, &by);
scanf("%I64d %I64d %I64d", &q.x, &q.y, &t);
while(1)
{
p[top].x = p[top-1].x * ax + bx;
p[top].y = p[top-1].y * ay + by;
//这边求下一个点的坐标时可能会爆LL,注意取合理的数据范围
//因为t小于等于10^16,且初始左边也小于等于10^16,所以这边坐标大于5*10^16之后的点就不在
//统计,因为他肯定到不了的。
if(p[top].x > 5e16 || p[top].y > 5e16)break;
top++;
}
for(i=0;i<top;i++)
{
if(dis(p[i], q) > t)continue;
LL sum = 0, dist = dis(p[i], q);
int num = 1;
for(j=i-1;j>=0;j--)
{
if(dist + dis(p[j+1], p[j]) > t)break;
num++;
dist += dis(p[j+1], p[j]);
}
ans = max(ans, num);
num = 1, dist = dis(p[i], q);
for(j=i+1;j<top;j++)
{
if(dist + dis(p[j-1], p[j])>t)break;
num++;
dist += dis(p[j-1], p[j]);
}
ans = max(ans, num);
}
printf("%d\n", ans);
return 0;
}
LL dis(node a, node b)
{
return llabs(a.x-b.x)+llabs(a.y-b.y);
}