当前位置: 代码迷 >> 综合 >> CF 1292【Div.1】B、CF 1293【Div2】 D——Aroma's Search【构造、暴力】
  详细解决方案

CF 1292【Div.1】B、CF 1293【Div2】 D——Aroma's Search【构造、暴力】

热度:92   发布时间:2023-12-16 22:56:20.0

题目传送门


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.


input

1 1 2 3 1 0
2 4 20

output

3

input

1 1 2 3 1 0
15 27 26

output

2

input

1 1 2 3 1 0
2 2 1

output

0


Note

In all three examples, the coordinates of the first 5 data nodes are (1,1), (3,3), (7,9), (15,27) and (31,81) (remember that nodes are numbered from 0).

In the first example, the optimal route to collect 3 nodes is as follows:

Go to the coordinates (3,3) and collect the 1-st node. This takes |3?2|+|3?4|=2 seconds.
Go to the coordinates (1,1) and collect the 0-th node. This takes |1?3|+|1?3|=4 seconds.
Go to the coordinates (7,9) and collect the 2-nd node. This takes |7?1|+|9?1|=14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:

Collect the 3-rd node. This requires no seconds.
Go to the coordinates (7,9) and collect the 2-th node. This takes |15?7|+|27?9|=26 seconds.
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.


题意

  • 标记的格子为 ( x i , y i ) (xi,yi) (xi,yi)
    x i = x i ? 1 ? a x + b x xi = xi-1 * ax + bx xi=xi?1?ax+bx
    y i = y i ? 1 ? a y + b y ; yi = yi-1 * ay + by; yi=yi?1?ay+by;
  • 出发点为 x s , y s xs,ys xs,ys。移动一格要一秒。求最多可以遍历几个标记的格子

题解

  • 容易看出标记格子函数方程单调,上凹函数。所以一直上或者一直下,取最优解即可。
  • 注意单方向走到头之后可能还剩余时间可以反向走。
  • 数据范围是个坑点,卡了几发,扩大即可
  • 暴力跑一边就可以了

AC-Code

#include <bits/stdc++.h>
using namespace std;
#define ll long longll  ax, ay, bx, by, xs, ys, t;
int cnt;
struct Node {
    ll x, y;}node[101];
ll dis(int a, int b) {
    return abs(node[a].x - node[b].x) + abs(node[a].y - node[b].y);
}
int solve1(int id) {
     // 下、上if (dis(id, 0) > t)	return 0;int ans = 0;ll time = t;int j = 0;for (int i = id; time > 0 && i > 0; --i) {
    if (dis(i, j) > time)	break;time -= dis(i, j);++ans;j = i;}for (int i = id + 1; time > 0 && i <= cnt; ++i) {
    if (dis(i, j) > time)	break;time -= dis(i, j);++ans;j = i;}return ans;
}
int solve2(int id) {
     // 上、下if (dis(id, 0) > t)	return 0;int ans = 0;ll time = t;int j = 0;for (int i = id; time > 0 && i <= cnt; ++i) {
    if (dis(i, j) > time)	break;time -= dis(i, j);++ans;j = i;}for (int i = id - 1; time > 0 && i > 0; --i) {
    if (dis(i, j) > time)	break;time -= dis(i, j);++ans;j = i;}return ans;}
int main() {
    
#define LIMIT (ll)1e16<<1 // 这里最开始是1e16,然后wa了;扩大点就好了ll x00, y00;while (cin >> x00 >> y00 >> ax >> ay >> bx >> by >> xs >> ys >> t) {
    cnt = 0;node[0].x = xs, node[0].y = ys;for (ll i = x00, j = y00; i <= LIMIT && j <= LIMIT; i = ax * i + bx, j = ay * j + by) {
    node[++cnt].x = i;node[cnt].y = j;}if (!cnt) {
    cout << 0 << endl;continue;}int ans = 0;for (int i = 1; i <= cnt; ++i) {
    ans = max(ans, max(solve1(i), solve2(i)));}cout << ans << endl;}return 0;
}

官方题解

#pragma GCC optimize("Ofast")#include <bits/stdc++.h>
using namespace std;#define endl '\n'long long x0, y0, ax, ay, bx, by, xs, ys, t;void Input() {
    cin >> x0 >> y0 >> ax >> ay >> bx >> by;cin >> xs >> ys >> t;
}void Solve() {
    vector<long long> x(1, x0), y(1, y0);long long LIMIT = (1LL << 62) - 1;while ((LIMIT - bx) / ax >= x.back() && (LIMIT - by) / ay >= y.back()) {
    x.push_back(ax * x.back() + bx); y.push_back(ay * y.back() + by);}int n = x.size();int ans = 0;for (int i=0; i<n; i++) {
    for (int j=i; j<n; j++) {
    long long length = x[j] - x[i] + y[j] - y[i];long long dist2Left = abs(xs - x[i]) + abs(ys - y[i]);long long dist2Right = abs(xs - x[j]) + abs(ys - y[j]);if (length <= t - dist2Left || length <= t - dist2Right) ans = max(ans, j-i+1);}}cout << ans << endl;
}int main(int argc, char* argv[]) {
    ios_base::sync_with_stdio(0); cin.tie(NULL);Input(); Solve(); return 0;
}
  相关解决方案