比赛:
牛客竞赛_ACM/NOI/CSP/CCPC/ICPC算法编程高难度练习赛_牛客竞赛OJ (nowcoder.com)
感想:
- 关于这次比赛,我其实想说的东西很多,因为确实并查集方面可能比较简单,然后都一样的套路,所以基本就是一些模板题,还有几道题,都是洛谷上的原题(不是原题意思都一样),优先队列之前学堆的时候也练习了一些题,说实话贪心+优先队列对我就有点像模板(主要是洛谷上的堆我做过了)我不太擅长思考一个算法是怎么来的,这算是缺点吧,所以我抓紧看看题解,补补我的题目。
1002
Running Median题解_gyr679的博客-CSDN博客
这题我真没看懂,(主要位运算啥也没学会,我都不好意思说。)
1006
P4404 [JSOI2010]缓存交换 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
就紫色的题目,我答案看的都很艰难。
1007
牛客网 【每日一题】6月11日题目精讲 背包_Jozky86的博客-CSDN博客
这道题我直接放弃(等我算法精深之后在看)
1009
#include<iostream>
#include <queue>
using namespace std;
const int N = 1e5 + 100, INF = 0x3f3f3f3f;
int a[N], vis[N], n[N], last[N];
priority_queue<pair<int, int>>q;
int main() {
int n1, m1, q1;
while (cin >> n1 >> m1 >> q1) {
while (!q.empty()) {
q.pop();
}
memset(vis, 0, sizeof(vis));
memset(n, 0, sizeof(n));
memset(last, INF, sizeof(last));
for (int i = 1; i <= q1; i++) {
cin >> a[i];
}
for (int i = q1; i >= 1; i--) {
n[i] = last[a[i]];
last[a[i]] = i;
}
int ans = 0;
for (int i = 1; i <= q1; i++) {
if (ans < n1 && !vis[a[i]]) {
ans++;
vis[a[i]] = 1;
}
else if (ans >= n1 && !vis[a[i]]) {
ans++;
vis[q.top().second] = 0;
vis[a[i]] = 1;
q.pop();
}
q.push({ n[i],a[i] });
}
cout << ans << endl;
}
}
1011
这道题因为有人问我了,实在不会,知道用优先队列来做,实在没想出来咋写,然后就去看的题解了,哎,还是有点内疚不是自己做出来的。
这个模板之后会总结的-》直接看我的代码:
#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
struct node {
int z, x, y;
bool operator < (const node& p)const {
return z < p.z;//作为分母,出来的那个要最大
}
}arr[300000];
int n;
bool cmp(node a, node b) {
return a.y < b.y;//这里对y进行排序,因为y是范围值
}
priority_queue<node>q;
int main()
{
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> arr[i].z >> arr[i].x >> arr[i].y;
}
sort(arr + 1, arr + 1 + n, cmp);
int time = 0;
int temp = 0;
double cnt = 0;
for (int i = 1; i <= n; i++)
{
q.push(arr[i]);
time += arr[i].x;
while (time > arr[i].y)//现在不满足这个条件了
{
node p = q.top();
q.pop();
temp = min(time - arr[i].y, p.x);//两者最小的才能保证金币个数最小
cnt += (1.0 * temp) / p.z;
time -= temp;//总的时间-用金币买掉的时间
p.x -= temp;//现在这个任务所需要完成的时间,只要不等于0装进去。
if (p.x != 0) {
q.push(p);
}
}
}
printf("%.1f\n", cnt);//注意输出
}