1 条题解
-
0
贪心
对数组排序后,遍历花种的位置,只要能选就一定选。判断是否能选可以计算上一个选取位置和当前位置的距离,若距离超过 ,则可以种。
#include<bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<LL, LL> PII; #define x first #define y second const int N = 2e5 + 10, M = 30; int a[N]; void solve() { int n, k, t; cin >> n >> k >> t; for(int i = 1; i <= k; i ++) cin >> a[i]; sort(a + 1, a + 1 + k); int last = -1e9, ans = 0; for(int i = 1; i <= k; i ++) { if(a[i] <= last + t - 1) ans ++; else last = a[i]; } cout << ans << endl; } int main() { ios::sync_with_stdio(0); cin.tie(0); int t = 1; // cin >> t; while(t --) solve(); }
- 1
信息
- ID
- 486
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 10
- 标签
- 递交数
- 9
- 已通过
- 3
- 上传者