1 条题解

  • 1
    @ 2024-11-9 20:28:50

    Consider the xx and yy directions separately and calculate the jumps we need in each direction. The number of jumps we need in the xx direction is xk\lceil \frac{x}{k} \rceil and similarily yk\lceil \frac{y}{k} \rceil in the yy direction. Now let's try to combine them to obtain the total number of jumps. Let's consider the following cases:

    1. yk\lceil \frac{y}{k} \rceilxk\lceil \frac{x}{k} \rceil. In this case, there will need to be yk\lceil \frac{y}{k} \rceilxk\lceil \frac{x}{k} \rceil extra jumps in the yy direction. While Freya performs these extra jumps, she will choose d=0d=0 for the xx direction. In total, there will need to be 2×2 \timesyk\lceil \frac{y}{k} \rceil jumps.

    2. xk\lceil \frac{x}{k} \rceil > yk\lceil \frac{y}{k} \rceil. We can use the same reasoning as the previous case, but there's a catch. Since Freya is initially facing the xx direction, for the last jump, she does not need to jump in the yy direction. In total, there will need to be 2×2 \timesxk1\lceil \frac{x}{k} \rceil−1 jumps.

    #include <bits/stdc++.h>
    using namespace std;
    #define ls u << 1
    #define rs u << 1 | 1
    #define LL long long
    #define int long long
    #define PII pair <int, int>
    #define fi first
    #define se second
    #define pub push_back
    #define pob pop_back
    #define puf push_front
    #define pof pop_front
    #define lb lower_bound
    #define ub upper_bound
    #define i128 __int128
    #define pcnt(x) __builtin_popcount(x)
    #define mem(a,goal) memset(a, (goal), sizeof(a))
    #define rep(x,start,end) for(int x = (start) - ((start) > (end)); x != (end) - ((start) > (end)); ((start) < (end) ? x ++ : x --))
    #define aLL(x) (x).begin(), (x).end()
    #define sz(x) (int)(x).size()
    const int INF = 998244353;
    const int P = 1e9 + 7;
    const int N = 1010;
    char g[N][N];
    void solve()
    {
        int x, y, k;
        cin >> x >> y >> k;
        int ans = 0;
        int l = ceil(x * 1.0 / k);//(x + k - 1) / k;上取整小技巧
        int r = ceil(y * 1.0 / k);
        if(l <= r) ans += r * 2;
        else ans += l * 2 - 1;
     
        cout << ans << '\n';
    }
    signed main()
    {
        int t;
        cin >> t;
        while(t --) solve();
        return 0;
    }
    
    • 1

    信息

    ID
    5471
    时间
    1000ms
    内存
    256MiB
    难度
    9
    标签
    (无)
    递交数
    12
    已通过
    3
    上传者