2024.12.24 周四
2024.12.24 周四
Q1. 1100
You are given an array
For each index
Q2. 1100
Monocarp is a student at Berland State University. Due to recent changes in the Berland education system, Monocarp has to study only one subject — programming.
The academic term consists of
Practical tasks are unlocked "each week" as the term goes on: the first task is unlocked on day
Every day from
Monocarp wants to have as many days off as possible, i. e. he wants to maximize the number of days he rests. Help him calculate the maximum number of days he can rest!
------------------------独自思考分割线------------------------
-
用时:35 28。Q1有点思维。Q2是3状态贪心。
A1.
- 排序之后发现前面的一定可以选取,后面到某一个临界值。假思路:二分,没有仔细证明答案二段性。
- 从当前向后一个个找复杂度较高,考虑快速查找,em.. 倒序考虑:
- 倒叙可行性的本质就是:利用后面的答案,先计算后面的答案可以让前面快速找到答案。遍历思想,数据维护,转移答案,有dp的味道。
A2.
- 那么一大堆就是:读好题意,贪心计算3个阶段。
------------------------代码分割线------------------------
A1.
#include <bits/stdc++.h>
#define int long long //
#define endl '\n' // 交互/调试 关
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cout << fixed << setprecision(6);
int T = 1;
cin >> T;
while (T--)
_();
return 0;
}
void _()
{
int n;
cin >> n;
struct Node
{
/* data */
int x, i, f;
};
vector<Node> a(n + 1);
for (int i = 1; i <= n; i++)
{
cin >> a[i].x;
a[i].i = i;
}
sort(a.begin() + 1, a.end(), [](Node &a, Node &b)
{ return a.x > b.x; });
vector<int> pre(n + 1);
for (int i = 1; i <= n; i++)
pre[i] = pre[i - 1] + a[i].x;
for (int i = 1; i <= n; i++)
if (i == 1)
a[i].f = n - 1;
else
{
if (pre[n] - pre[i - 1] >= a[i - 1].x)
a[i].f = a[i - 1].f;
else
a[i].f = n - i;
}
sort(a.begin(), a.end(), [](Node &a, Node &b)
{ return a.i < b.i; });
for (int i = 1; i <= n; i++)
cout << a[i].f << " ";
cout << endl;
}
// void _()
// {
// int n;
// cin >> n;
// struct Node
// {
// /* data */
// int x, i, res;
// };
// vector<Node> a(n + 1);
// for (int i = 1; i <= n; i++)
// {
// cin >> a[i].x;
// a[i].i = i;
// }
// sort(a.begin(), a.end(), [](Node &a, Node &b)
// { return a.x < b.x; });
// vector<int> pre(n + 1);
// for (int i = 1; i <= n; i++)
// pre[i] = pre[i - 1] + a[i].x;
// auto ok = [&](int x)
// {
// return pre[x - 1] >= a[x].x;
// };
// for (int i = 1; i <= n; i++)
// {
// int l = i, r = n + 1;
// while (r - l - 1)
// {
// int mid = l + r >> 1;
// if (ok(mid))
// l = mid;
// else
// r = mid;
// }
// bug2(i, l);
// a[i].res = l - 1;
// }
// sort(a.begin(), a.end(), [](Node &a, Node &b)
// { return a.i < b.i; });
// for (int i = 1; i <= n; i++)
// cout << a[i].res << " ";
// cout << endl;
// }
A2.
#include <bits/stdc++.h>
#define int long long //
#define endl '\n' // 交互/调试 关
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cout << fixed << setprecision(6);
int T = 1;
cin >> T;
while (T--)
_();
return 0;
}
void _()
{
int n, p, t, l;
cin >> n >> p >> l >> t;
auto cal = [](int a, int b)
{
return (a + b - 1) / b;
};
int has = cal(n, 7);
int ned = cal(p, t * 2 + l);
int res = min(has / 2, ned);
p -= res * (t * 2 + l);
// bug(p);
if (p > 0)
{
if (has & 1)
res++, p -= t + l;
}
if (p > 0)
res += cal(p, l);
res = min(res, n);
cout
<< n - res << endl;
}
// void _()
// {
// int n, p, t, l;
// cin >> n >> p >> l >> t;
// auto cal = [](int a, int b)
// {
// return (a + b - 1) / b;
// };
// int has = cal(n, 7);
// int ned = cal(p, t * 2 + l);
// int res = min(has, ned);
// if (ned > has)
// {
// p -= has * (t * 2 + l);
// res += cal(p, l);
// res = min(n, res);
// }
// cout << n - res << endl;
// }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!