当前位置:网站首页>【集训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;
}
边栏推荐
- Interpretation of the source code of all logging systems in XXL job (line by line source code interpretation)
- 三菱FX PLC自由口RS指令实现MODBUS通讯
- ML-Numpy
- Which is reliable between qiniu business school and WeiMiao business school? Is it safe to open an account recommended by the teacher?
- 3dslicer introduction and installation tutorial
- Why is the integer type 128 to byte -128
- Xiaobai programmer the next day
- Data quality: the core of data governance
- Leetcode 106. construct binary tree from middle order and post order traversal sequence
- torchvision
猜你喜欢

3dslicer import cone beam CT image

3dslicer importing medical image data

4day

Using simple scripts to process data in 3dslicer

SQL中in的用法 DQL 查询

C语言逆序打印字符串的两种方法

TFrecord写入与读取

H5幸运刮刮乐抽奖 免公众号+直运营

Xiaobai programmer's sixth day

Pyspark data analysis basis: pyspark.sql.sparksession class method explanation and operation + code display
随机推荐
Xiaobai programmer day 8
On the difference between break and continue statements
VIM usage record
Wkid in ArcGIS
Method of converting MAPGIS format to ArcGIS
xss-工具-Beef-Xss安装以及使用
3 词法分析
编译器引论
MapGIS格式转ArcGIS方法
About vscode usage+ Solutions to the problem of tab failure
Randomly generate 10 (range 1~100) integers, save them to the array, and print the array in reverse order. And find the average value, the maximum value and the subscript of the maximum value, and fin
Perform Jieba word segmentation on the required content and output EXCEL documents according to word frequency
Don't vote, software testing posts are saturated
SQL基本语句 DQL select与提取 DML插入删除
Xiaobai programmer's sixth day
Win10 set up a flutter environment to step on the pit diary
Smart S7-200 PLC channel free mapping function block (do_map)
Square root of X
Synchronized and volatile
Use of hyperlinks