A:各捆干草间互相独立,所以优先移动距 \(1\) 近的。
点击查看代码
#include<bits/stdc++.h>
#define int long long
#define psbk push_back
#define fst first
#define scd second
#define umap unordered_map
#define pqueue priority_queue
#define vc vector
#define endl '\n'
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
constexpr int inf = 0x3f3f3f3f;
int n, d, a[105];
void solve()
{
cin >> n >> d;
int ans = 0;
for(int i=1;i<=n;i++)
{
cin >> a[i];
if(i == 1)
{
ans = a[1];
}
else
{
ans += min(a[i], d / (i - 1));
d -= min(a[i], d / (i - 1)) * (i - 1);
}
}
cout << ans << endl;
}
signed main()
{
// freopen("1.in","r",stdin);
// freopen("1.out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int tt;
cin >> tt;
while(tt--)
{
solve();
}
return 0;
}
B:首先,若存在 \(i\) 使得 \(a_i=x\),显然答案为 \(1\)。
否则,令 \(mx=\max_{i=1}^na_i\),当距离 \(>2\times mx\) 时不断向右跳,然后再跳 \(2\) 次,一定可以到达。
点击查看代码
#include<bits/stdc++.h>
#define int long long
#define psbk push_back
#define fst first
#define scd second
#define umap unordered_map
#define pqueue priority_queue
#define vc vector
#define endl '\n'
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
constexpr int inf = 0x3f3f3f3f;
int n, x, a[100005];
void solve()
{
cin >> n >> x;
int mx = -1e18;
for(int i=1;i<=n;i++)
{
cin >> a[i];
mx = max(mx, a[i]);
}
for(int i=1;i<=n;i++)
{
if(a[i] == x)
{
cout << 1 << endl;
return;
}
}
cout << max((x - 1 - mx) / mx, 0ll) + 2 << endl;
}
signed main()
{
// freopen("1.in","r",stdin);
// freopen("1.out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int tt;
cin >> tt;
while(tt--)
{
solve();
}
return 0;
}
C:
标签:typedef,int,2024.9,long,solve,CF1307,mx,模拟,define From: https://www.cnblogs.com/Byf23333/p/18400836