社区讨论
考场猎奇代码AC
P14635[NOIP2025] 糖果店参与者 3已保存回复 2
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 2 条
- 当前快照
- 1 份
- 快照标识符
- @miriu08u
- 此快照首次捕获于
- 2025/12/04 22:18 3 个月前
- 此快照最后确认于
- 2025/12/06 21:42 3 个月前
贪心思路没想出来,打算骗分结果A了
CPP#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int maxn = 1e6+5;
using pii = pair<int, int>;
struct node {
int x, y;
} candies[maxn];
int n, m, minsum = INT_MAX, res, minid, bought[maxn], flag;
priority_queue<int, vector<int>, greater<int>> q;
void solve1() {
sort(candies + 1, candies + n + 1, [](node a, node b) {
return a.x + a.y == b.x + b.y ? a.x > b.x : a.x + a.y < b.x + b.y;
});
minsum = candies[1].x + candies[1].y;
sort(candies + 2, candies + n + 1, [](node a, node b) {
return a.x < b.x;
});
for (int i = 2; i <= n; i++) {
if (candies[i].x <= minsum / 2) {
res++;
m -= candies[i].x;
bought[i] = 1;
}
}
res += m / minsum * 2;
m %= minsum;
for (int i = 1; i <= n; i++) {
if (bought[i])q.push(candies[i].y);
else q.push(candies[i].x);
}
while (q.size()) {
if (m >= q.top()) m -= q.top(), res++, q.pop();
else q.pop();
}
cout << res;
}
void solve2() {
sort(candies + 1, candies + n + 1, [](node a, node b) {
return a.x + a.y == b.x + b.y ? a.x > b.x : a.x + a.y < b.x + b.y;
});
minsum = candies[1].x + candies[1].y;
sort(candies + 1, candies + n + 1, [](node a, node b) {
return a.x < b.x;
});
res += (m / minsum) * 2;
m %= minsum;
for (int i = 1; i <= n; i++) if (m >= candies[i].x) m -= candies[i].x, res++;
cout << res;
}
signed main() {
freopen("candy.in","r",stdin);
freopen("candy.out","w",stdout);
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> candies[i].x >> candies[i].y;
if (candies[i].x < candies[i].y) flag = 1;
}
if (flag) solve1();
else solve2();
return 0;
}
回复
共 2 条回复,欢迎继续交流。
正在加载回复...