链接:https://codeforces.com/contest/1293/problem/D
KIVΛ & Nikki Simmons - Perspectives
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 00, with their coordinates defined as follows:
Initially Aroma stands at the point (xs,ys)(xs,ys). She can stay in OS space for at most tt 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)(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 tt seconds?
Input
The first line contains integers x0x0, y0y0, axax, ayay, bxbx, byby (1≤x0,y0≤10161≤x0,y0≤1016, 2≤ax,ay≤1002≤ax,ay≤100, 0≤bx,by≤10160≤bx,by≤1016), which define the coordinates of the data nodes.
The second line contains integers xsxs, ysys, tt (1≤xs,ys,t≤10161≤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 tt seconds.
Examples
input
Copy
1 1 2 3 1 0 2 4 20
output
Copy
3
input
Copy
1 1 2 3 1 0 15 27 26
output
Copy
2
input
Copy
1 1 2 3 1 0 2 2 1
output
Copy
0
Note
In all three examples, the coordinates of the first 55 data nodes are (1,1)(1,1), (3,3)(3,3), (7,9)(7,9), (15,27)(15,27) and (31,81)(31,81) (remember that nodes are numbered from 00).
In the first example, the optimal route to collect 33 nodes is as follows:
In the second example, the optimal route to collect 22 nodes is as follows:
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that.
代码:
#include<bits/stdc++.h>
using namespace std;
long long n,k,l,r,s,t,q,x,y,ax,ay,bx,by,xs,ys;
int max1=0;
map<long long,long long>m[2];
long long a[100005],b[100005];
int main()
{
cin>>x>>y>>ax>>ay>>bx>>by;
cin>>xs>>ys>>t;
s=0;
a[0]=x;
b[0]=y;
while(1)
{
s++;
a[s]=a[s-1]*ax+bx;
b[s]=b[s-1]*ay+by;
if(a[s]-xs>t||b[s]-ys>t)
break;
}
for(int i=0;i<=s;i++)
{
for(int j=0;j<=s;j++)
{
if(fabs(a[i]-xs)+fabs(b[i]-ys)+fabs(a[i]-a[j])+fabs(b[i]-b[j])<=t)
max1=max(max1,abs(i-j)+1);
}
}
cout<<max1;
}