当前位置:网站首页>【集训DAY11】Nescafe【贪心】
【集训DAY11】Nescafe【贪心】
2022-07-25 22:24:00 【VL——MOESR】

思路:
我们直接贪心,按e从小到大来取。
因为不管e是多少,取了它贡献就只有1,那肯定是取最小的好
c o d e code code
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int n, fa[10010], edg[10010], ans;
struct node {
int val, id;
}a[10010];
bool cmp(node x, node y) {
return x.val < y.val;
}
int main() {
scanf("%d", &n);
for(int i = 1; i <= n; i ++) {
scanf("%d%d%d", &fa[i], &a[i].val, &edg[i]);
a[i].id = i;
}
sort(a + 1, a + 1 + n, cmp);
for(int i = 1; i <= n; i ++) {
bool flag = 0;
for(int j = a[i].id; j; j = fa[j])
if(edg[j] < a[i].val) {
flag = 1; break; }
if(flag) continue;
for(int j = a[i].id; j; j = fa[j]) edg[j] -= a[i].val;
ans ++;
}
printf("%d", ans);
return 0;
}
边栏推荐
猜你喜欢

Wechat card issuing applet source code - automatic card issuing applet source code - with flow main function

What is partition and barrel division?

2day

关于getchar和scanf的使用示例及注意点

Get together for ten years, tell your story, millions of gifts are waiting for you

Playwright tutorial (I) suitable for Xiaobai

win10搭建flutter环境踩坑日记

QML module not found

Arcgis10.2 configuring postgresql9.2 standard tutorial

Playwright tutorial (II) suitable for Xiaobai
随机推荐
启牛商学院和微淼商学院哪个靠谱?老师推荐的开户安全吗?
Ffmpeg plays audio and video, time_ Base solves the problem of audio synchronization and SDL renders the picture
[C syntax] void*
数学规划分类 Math Programming Classfication
Don't vote, software testing posts are saturated
ML-Numpy
Mitsubishi FX PLC free port RS command realizes Modbus Communication
Recursive case -c
SQL basic statement DQL select and extract DML insert delete
Builder pattern
Square root of X
H5 lucky scratch lottery free official account + direct operation
(1) Integrating two mapping frameworks of Dao
QML module not found
2day
如何将一个域名解析到多个IP地址?
Advanced database · how to add random data for data that are not in all user data - Dragonfly Q system users without avatars how to add avatar data - elegant grass technology KIR
Smart S7-200 PLC channel free mapping function block (do_map)
Wechat official account application development (I)
对需求的内容进行jieba分词并按词频排序输出excel文档