1 条题解
-
1
Consider the and directions separately and calculate the jumps we need in each direction. The number of jumps we need in the direction is and similarily in the direction. Now let's try to combine them to obtain the total number of jumps. Let's consider the following cases:
-
≥ . In this case, there will need to be − extra jumps in the direction. While Freya performs these extra jumps, she will choose for the direction. In total, there will need to be jumps.
-
> . We can use the same reasoning as the previous case, but there's a catch. Since Freya is initially facing the direction, for the last jump, she does not need to jump in the direction. In total, there will need to be 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
- 上传者