
贪心
小菜鸡在努力啊
余生很长,请多指教。
展开
-
P1803
P1803 优先选择结束时间最早的。 #include<bits/stdc++.h> using namespace std; const int maxn=1000005; struct node{ int t1,t2; }s[maxn]; int n; bool cmp(const node &a,const node &b){ return a.t2<b.t2; } int ans,t; int main(){ cin>>n; for(int i=原创 2020-06-05 23:11:16 · 230 阅读 · 0 评论 -
P3817 小A的糖果(贪心)
P3817 当相邻的两盒大于x到时候,应该先吃那一盒呢? 答案:正着遍历,吃后面;反着遍历,吃前面! 为什么是这样的呢? 比如一个样例: 5 6 4 5 3 6 2 此时,若正着遍历,4+5>6,如果吃4(a[1]),就考虑不到a[3],吃5(a[2])则一举两得。 #include <bits/stdc++.h> using namespace std; typedef long long ll; ll n,x; ll a[100005]; ll ans; int main() {原创 2020-06-05 23:09:09 · 250 阅读 · 0 评论 -
P1090 合并果子(优先队列 贪心)
P1090 题目描述 在一个果园里,多多已经将所有的果子打了下来,而且按果子的不同种类分成了不同的堆。多多决定把所有的果子合成一堆。 每一次合并,多多可以把两堆果子合并到一起,消耗的体力等于两堆果子的重量之和。可以看出,所有的果子经过 n-1n−1 次合并之后, 就只剩下一堆了。多多在合并果子时总共消耗的体力等于每次合并所耗体力之和。 因为还要花大力气把这些果子搬回家,所以多多在合并果子时要尽可能地节省体力。假定每个果子重量都为 11 ,并且已知果子的种类 数和每种果子的数目,你的任务是设计出合并的次序方案原创 2020-06-02 22:16:25 · 264 阅读 · 0 评论 -
P2240 【深基12.例1】部分背包问题
洛谷P2240 贪心,每次都尽可能的拿性价比最好的。 #include<iostream> #include<algorithm> #include<cstdio> using namespace std; struct node{ double w,p,t; }d[150]; bool cmp(const node &a,const node &b) { return a.t>b.t; } int main(){ int n,t; cin原创 2020-06-02 21:55:13 · 181 阅读 · 0 评论