枚举每个点,然后先由起点走到这个点,再“先左后右”地处理,为什么会WA?
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PII;
#define mp make_pair
ll xx, yy, ax, ay, bx, by, xs, ys, t, xbound, ybound, ans;
PII p1, p2;
vector<PII> p;
ll mht(PII x, PII y) {
ll d1 = labs(x.first - y.first), d2 = labs(x.second - y.second);
if(d1 + d2 < 0) return LLONG_MAX >> 1;
return d1 + d2;
}
ll solve(int pos) {
if(mht(p[pos], mp(xs, ys)) > t) return 0;
int temp = pos, res = 1; ll cost = mht(p[pos], mp(xs, ys));
while(pos > 0) {
cost += mht(p[pos], p[pos - 1]);
if(cost > t) { cost -= mht(p[pos], p[pos - 1]); break; }
pos -- ; res ++ ;
}
if(temp == (int)p.size() - 1 || mht(p[pos], p[temp + 1]) + cost > t) return res;
cost += mht(p[pos], p[temp + 1]); pos = temp + 1; res ++ ;
while(pos < p.size() - 1) {
cost += mht(p[pos], p[pos + 1]);
if(cost > t) return res;
pos ++ ; res ++ ;
}
return res;
}
int main() {
cin >> xx >> yy >> ax >> ay >> bx >> by >> xs >> ys >> t;
p.push_back(mp(xx, yy));
xbound = (LLONG_MAX / 2 - bx) / ax;
ybound = (LLONG_MAX / 2 - by) / ay;
while(p[p.size() - 1].first < xbound && p[p.size() - 1].second < ybound) {
PII tp = p[p.size() - 1];
p.push_back(mp(ax * tp.first + bx, ay * tp.second + by));
}
for(unsigned i = 0; i < p.size(); i ++ )
ans = max(ans, solve(i));
cout << ans << endl;
return 0;
}