![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
贪心
wwt9b15bs
这个作者很懒,什么都没留下…
展开
-
【题解】洛谷P1525关押罪犯[NOIP2010] 并查集+贪心
题目链接 最开始我写的最小生成树……后来发现理解错题意了 参考了大佬题解其中合并敌人的敌人这种操作非常巧妙#include<cstdio>#include<cstring>#include<climits>#include<cstring>#include<algorithm&原创 2018-08-18 07:38:00 · 229 阅读 · 0 评论 -
【题解】洛谷P1031均分纸牌[NOIP2002] 贪心+模拟
题目链接/*模拟 从前往后扫描数组,判断距离平均数还差几张如果小于平均数,则用后面那张补过来如果大于平均数,则往后补*/#include<cstdio>int a[110];int main(){ int t,n,i,step=0,sum=0; scanf("%d",&n); for(i=1;i<=n;i++){ ...原创 2018-09-01 08:14:05 · 209 阅读 · 0 评论 -
【题解】洛谷P1233木棍加工 贪心
题目链接 按照长度降序排序,再根据宽度来算。#include<cstdio>#include<algorithm>using namespace std;#define _rep(i,a,b) for(int i=(a);i<=(b);i++)const int N=5e3+10;int n,vis[N];struct node{ int...原创 2018-09-01 08:14:09 · 320 阅读 · 0 评论 -
【题解】洛谷P2123皇后游戏 贪心
题目链接 根据国王游戏的经验,尝试着用微扰证明,结果证明过程有误,学习了大佬题解以后发现我的证明过程确实存在问题。#include<cstdio>#include<algorithm>#include<cmath>using namespace std;#define _rep(i,a,b) for(int i=原创 2018-09-07 07:15:50 · 240 阅读 · 0 评论 -
【题解】hdu4864 贪心
题目链接#include<cstdio>#include<cstring>#include<algorithm>using namespace std;typedef long long ll;#define _rep(i,a,b) for(int i=(a);i<=(b);i++)const int N=1e5+10;int n,m原创 2018-09-04 10:43:18 · 129 阅读 · 0 评论 -
【题解】bzoj2457 贪心+排序
题目链接 大概思路倒是晓得,代码实现还是有点迷。 大佬题解写的非常好#include<cstdio>#include<algorithm>using namespace std;#define _rep(i,a,b) for(int i=(a);i<=(b);i++)const int N=2e5+10;int n,ans,mx[N],mi[N]...原创 2018-09-05 07:18:05 · 423 阅读 · 0 评论 -
【题解】poj3614 贪心
题目链接 按照minSPF递减的顺序排序,再选择可用的SPF最大的防晒霜#include<cstdio>#include<algorithm>using namespace std;#define _rep(i,a,b) for(int i=(a);i<=(b);i++)const int N=2510; int c,l,ans;struct n...原创 2018-08-27 15:53:00 · 229 阅读 · 0 评论 -
【题解】poj1050 T0 the Max 贪心
题目链接DescriptionGiven a two-dimensional array of positive and negative integers, a sub-rectangle is any contiguous sub-array of size 1*1 or greater located within the whole array. The sum of a rect...原创 2018-09-10 07:17:32 · 195 阅读 · 0 评论 -
【题解】codeforces1029B[Codeforces Round #506 (Div. 3)]B.Creating the Contest 贪心
题目链接DescriptionYou are given a problemset consisting of nnn problems. The difficulty of the iii-th problem is aia_iai. It is guaranteed that all difficulties are distinct and are given in the incre...原创 2018-09-24 14:57:50 · 275 阅读 · 0 评论 -
【题解】洛谷P1803凌乱的yyy 贪心
题目链接#include<cstdio>#include<algorithm>using namespace std;struct node{ int a,b;}q[1000010];int cmp(const node&x,const node&y){ return x.b<y.b;}int main(){原创 2018-09-01 08:14:02 · 156 阅读 · 0 评论 -
【题解】洛谷P1094纪念品分组[NOIP2007普及] 贪心
题目链接#include<cstdio>#include<algorithm>using namespace std;int a[50000],b[50000];int cmp(const int&a,const int&b){ return a>=b;}int main(){ int cnt=0,j,x,sum,i,w原创 2018-09-01 08:13:58 · 206 阅读 · 0 评论 -
【题解】洛谷P1223排队接水 贪心
题目链接#include<cstdio>struct node{ int id,t;}q[2000],temp;int main(){ //freopen("in.txt","r",stdin); int n,i,j; long long sum=0; scanf("%d",&n);原创 2018-09-01 08:13:50 · 349 阅读 · 0 评论 -
【题解】sdoj2796(同bzoj5088 hdu6000 雅礼集训2017Day4)(2018-08-11集训T3) 优先队列+贪心
题目链接题目描述你现在要洗 l 件衣服。你有 n 台洗衣机和 m 台烘干机。由于你的机器非常的小,因此你每次只能洗涤(烘干)一件衣服。 第 i台洗衣机洗一件衣服需要 wi 分钟,第 i 台烘干机烘干一件衣服需要 di 分钟。 请问把所有衣服洗干净并烘干,最少需要多少时间?假设衣服在机器间转移不需要时间,并且洗完的衣服可以过一会再烘干。输入输入文件的第一行三个整数 l 、n 和 ...原创 2018-08-11 16:04:53 · 208 阅读 · 0 评论 -
【题解】洛谷P1090合并果子[NOIP2004] 优先队列+贪心
每次选和最小的两堆合并就好。在被之前的一道堆优化贪心的比赛题蹂躏之后感觉有经验了,之前看过这题都没啥思路的。#include<cstdio>#include<queue>#define _rep(i,a,b) for(int i=(a);i<=(b);i++)using namespace std;int main(){ //freo原创 2018-08-13 07:01:17 · 244 阅读 · 0 评论 -
【题解】poj3190 贪心+堆优化
题目链接 按照开始吃草的时间把牛排序。用一个小根堆维护每个畜栏最后一头牛结束吃草的时间,尝试把当前的牛安排在堆顶#include<cstdio>#include<algorithm>#include<queue>using namespace std;#define _rep(i,a,b) for(int i=(a);i<=(b);i++原创 2018-08-27 15:53:19 · 209 阅读 · 0 评论 -
【题解】poj1328 贪心
题目链接 对于每个区间,优先选择已有的监控设备管辖它 如果当前区间左端点大于最后一台监控设备右端点,新增一台设备,否则更新最后一台监控的位置#include<cstdio>#include<cmath>#include<algorithm>using namespace std;#define _rep(i,a,b) for(int i=(a);...原创 2018-08-27 15:53:27 · 143 阅读 · 0 评论 -
【题解】洛谷P1080国王游戏[NOIP2012Day1T2] 贪心
题目链接 按照每个大臣左右手上的数的乘积从小到大排序,就是最优排队方案 可以使用微扰证明,详见李煜东的算法竞赛进阶指南#include<cstdio>#include<algorithm>#include<cstring>using namespace std;struct node{ int a,b,c;}q[2000];int a...原创 2018-08-27 15:53:37 · 338 阅读 · 0 评论 -
【题解】poj2054 复杂的贪心
题目链接 大佬博客的讲解非常详细,学习了 详细思路见上方博客或者李煜东《算法竞赛进阶指南》#include<cstdio>#include<cstring>#include<vector>using namespace std;#define _rep(i,a,b) for(int i=(a);i<=(b);i++)#define _原创 2018-08-27 15:54:10 · 334 阅读 · 0 评论 -
【题解】poj1456 并查集+贪心
题目链接 贪心思想,按照利润大到小排序,优先安排。对于每个商品,在它能卖出的最晚时间卖出。可以用并查集来实现。建立一个关于“天数”的并查集。对于一个商品,如果在d天后过期,就查询d的树根r。如果r大于0,则安排在第r天卖出,令r为r-1的子节点。#include<cstdio>#include<algorithm>using namespace std;#d...原创 2018-09-01 08:13:26 · 326 阅读 · 0 评论 -
【题解】洛谷P1181数列分段 贪心
题目链接#include<cstdio>int a[100010];int main(){ int sum=0,i,n,m,cnt=1; scanf("%d%d",&n,&m); for(int i=1;i<=n;i++){ scanf("%d",&a[原创 2018-09-01 08:13:41 · 195 阅读 · 0 评论 -
【题解】洛谷P1208[USACO1.3] 贪心
题目链接#include<cstdio>#include<iostream>using namespace std; struct node{ int p,i;}q[10000];int main(){ //freopen("in.txt","r",stdin); int i,j,x,ans=0,k,n,m;原创 2018-09-01 08:13:46 · 205 阅读 · 0 评论 -
【题解】洛谷P1417烹调方案 01背包+贪心
题目链接最初以为这就是一个01背包问题。设 dp[i,j]dp[i,j]dp[i,j] 表示前 iii 项食材用时为 jjj 时的最大美味指数。dp[i,j]=maxc[i]≤j≤t{dp[i−1][j−c[i]]+a[i]−j×b[i]}dp[i,j]=\max\limits_{c[i]\leq j\leq t}\{dp[i-1][j-c[i]]+a[i]-j\times b[i]...原创 2018-10-14 21:32:46 · 221 阅读 · 0 评论