首页 > TAG信息列表 > Protecting
Protecting the flowers 贪心
题目: https://ac.nowcoder.com/acm/problem/25043 //思路:需要推出贪心的式子,后面的和接水一个原理 #include<stdio.h>#include<algorithm>using namespace std;const int maxn=1e5+7;struct no{ int d,t;};int cmp(no a,no b){ return a.t*b.d<a.d*b.t;}int main(){struct nProtecting the Flowers 牛客题解
Protecting the Flowers 题目链接:传送门 链接:https://ac.nowcoder.com/acm/problem/25043 来源:牛客网 Farmer John went to cut some wood and left N (2 ≤ N ≤ 100,000) cows eating the grass, as usual. When he returned, he found to his horror that the cluster of[USACO07JAN]Protecting the Flowers S
一看题面就知道是贪心 随便搞一搞就好了 题目传送门 sol 贪心+排序 对于牛的排序:a.t * b.d<a.d * b.t (手动推一推就好了) 读入的时候,将所有牛每分钟所吃的花数总和统计起来,然后循环中按照顺序,先把当前所要运走的牛吃花的数量减去,然后用剩下的花的总数乘上所要运走的牛的时间t*2(往神兽、佛祖保佑,代码全程无bug
''' ━━━━━━神兽出没━━━━━━ ┏┓ ┏┓ ┏┛┻━━━━━┛┻┓ ┃ ┃ ┃ ━ ┃ ┃ ┳┛ ┗┳ ┃ ┃ ┃ ┃ ┻ ┃ ┃ ┃ ┗━┓ ┏━┛ Code is far away from bug with