随笔分类 -  贪心

1
摘要:problem在一条直线上有n个坑,要种k棵树。不能在相邻两个坑种树。已知在每个坑种树会有一个获利,求最大获利。n#includeusing namespace std;const int maxn = 5e5+10;struct node{ int id, v... 阅读全文
posted @ 2018-08-08 08:13 gwj1139177410 阅读(199) 评论(0) 推荐(0)
摘要:problem有n个人,第i个人重量ai每艘船载重为w,最多可乘2个人求能装载所有人的最少的船数n #includeusing namespace std;const int maxn = 30010;int a[maxn];int main(){ int w,... 阅读全文
posted @ 2018-07-23 21:12 gwj1139177410 阅读(192) 评论(0) 推荐(0)
摘要:problemsolutioncodes#include#includeusing namespace std;const int maxn = 110;int a[maxn], b[maxn], c[maxn];bool cmp(int x, int y){ ... 阅读全文
posted @ 2018-06-05 21:21 gwj1139177410 阅读(99) 评论(0) 推荐(0)
摘要:problemsolutioncodes/*贪心1.找出不互质的数的集合,就是把互斥的数删去.2.那么当有两个互斥的数时,如果删掉前面(小)的,这个数后面的与它互斥的数也会入选,所以删掉后面的更优。3.因为每个数都是不同的。*/#include#include#inc... 阅读全文
posted @ 2018-06-05 21:18 gwj1139177410 阅读(217) 评论(0) 推荐(0)
摘要:problemsolutioncodes//优先打价值最大的(如果能打的化)#include#includeusing namespace std;struct d{ int t, w; }a[110];bool cmp(d a, d b){ return a.w>=... 阅读全文
posted @ 2018-06-05 21:16 gwj1139177410 阅读(131) 评论(0) 推荐(0)
摘要:problemsolutioncodes//f[i]:第i秒最远可以走多远#includeusing namespace std;const int maxn = 300010;int m, s, t, f[maxn];int main(){ cin>>m>>s... 阅读全文
posted @ 2018-06-04 21:36 gwj1139177410 阅读(159) 评论(0) 推荐(0)
摘要:problem一个有n个数的环每次只能向相邻的数移动,移动一个数代价为1求让所有数相等的最小代价solution一:思路 1、纸牌均分问题每行答案是∑i=1n|i∗T/n−G[i]|" role="presentation" ... 阅读全文
posted @ 2018-05-30 12:31 gwj1139177410 阅读(156) 评论(0) 推荐(0)
摘要:problemn个建筑需要抢修第i个建筑需要T1时间抢修,必须在T2时间之前抢修完毕求最多能抢修多少建筑solution先按照 t2 从小到大排列(对于每一个建筑,我们肯定等它快到限制的时候再修复它。)对于一个建筑,如果能修理就修理;如果不能修,就比较他和前面修理了的... 阅读全文
posted @ 2018-05-28 20:15 gwj1139177410 阅读(118) 评论(0) 推荐(0)
摘要:problemsolutioncodes#includeusing namespace std;int main(){ unsigned int n, x; while(cin>>n &&n){ x = n&-n; cout<<... 阅读全文
posted @ 2018-05-26 13:24 gwj1139177410 阅读(110) 评论(0) 推荐(0)
摘要:problem有n只怪打败第i只怪物,消耗d[i]点生命值,恢复a[i]点生命值。任何时候你的生命值都不能降到0(或0以下)请问是否存在一种打怪顺序,使得你可以打完这n只怪物而不死掉n #includeusing namespace std;const int max... 阅读全文
posted @ 2018-05-24 21:01 gwj1139177410 阅读(128) 评论(0) 推荐(0)
摘要:problem平面直角坐标系上有n个点。在x轴上找尽量少的点,并以这些点为圆心画一个半径为d的圆,使得给定的点都在画出来的圆里。求最少要画的点数,如果不能输出-1。solution一、不能的情况 当且仅当,x轴上所有点到该点的距离都超过了d(即最短距离情况下,他到x轴... 阅读全文
posted @ 2018-05-24 20:45 gwj1139177410 阅读(101) 评论(0) 推荐(0)
摘要:problemsolutioncodes//mdzz计算机根本不可能会赢???#include#define maxn 510using namespace std;int a[maxn][maxn], ans;int main(){ int n; cin>>... 阅读全文
posted @ 2018-05-24 13:31 gwj1139177410 阅读(126) 评论(0) 推荐(0)
摘要:problemn个人,每个人左手右手各写有一个数字。把n个人排成一列,每个人得到的奖金是前面所有人左手上数字的乘积除以自 己右手上的数字下取整。最小化每个人奖金的最大值。solution一、贪心: + 按左手数字乘右手数字从小到大排序 + 小的在前,大的在后二、证明:... 阅读全文
posted @ 2018-05-23 21:15 gwj1139177410 阅读(266) 评论(0) 推荐(0)
摘要:problem有n堆果子每次可以将两堆果子合并,代价为新堆的果子数。求把所有果子合并成一堆的最小代价。solution每次合并最小的两堆用堆或者两个队列维护证明?反证法。codes#include#includeusing namespace std;priority... 阅读全文
posted @ 2018-05-21 21:43 gwj1139177410 阅读(119) 评论(0) 推荐(0)
摘要:problemn头奶牛要在指定的时间内吃草,而一个机器只能同时给一个奶牛吃草。给你每头奶牛吃草的开始时间和结束时间,问你最小需要多少机器和每头牛对应的方案。 n#include#includeusing namespace std;const int maxn = 5... 阅读全文
posted @ 2018-05-21 21:26 gwj1139177410 阅读(109) 评论(0) 推荐(0)
摘要:problem有C个奶牛去晒太阳,第i头奶牛需要minSPF[i]和maxSPF[i]单位强度之间的阳光。每头奶牛晒太阳之前要涂防晒霜,防晒霜有L种,涂上第i种以后阳光强度就会稳定为SPF[i],第i种防晒霜有cover[i]瓶。求最多可以满足多少头奶牛晒太阳。(1 ... 阅读全文
posted @ 2018-05-21 20:39 gwj1139177410 阅读(187) 评论(0) 推荐(0)
摘要:题解显然纸牌总数必为n的倍数,否则无解(题目也说了每个人和平均数(最后的纸牌数)差多少,就要从旁边的人手中拿多少张牌。即使某个时刻某人手中的牌是负数也没有关系,可以认为是他a[i]从a[i+1]手中拿牌发生在a[i-1]从a[i]手中拿牌之前。所以,直接算出平均数。 ... 阅读全文
posted @ 2018-05-12 13:17 gwj1139177410 阅读(150) 评论(0) 推荐(0)
摘要:题面传送门 传送门2题解如果没有相邻限制的话,我们开一个大根堆每一次取最大的就行了,但是如果存在限制,我们就加入一个后悔操作,来做调整贪心。 首先如果我们选择了一个点i,那么其相邻的点i−1,i+1,都不能选了,所以我们删除这两个点,因为i与它们两个是互斥的。 所以我... 阅读全文
posted @ 2018-04-24 21:28 gwj1139177410 阅读(158) 评论(0) 推荐(0)
摘要://UVa1149 - Bin Packing//贪心,背包,乘船问题#include#includeusing namespace std;int a[101000]; //bagint main(){ //freopen("UVa1149.in","r",stdi... 阅读全文
posted @ 2017-04-03 09:47 gwj1139177410 阅读(93) 评论(0) 推荐(0)
摘要://UVa12545 - Bits Equalizer//贪心#include#define MIN(X,Y) (((X)>(Y))?(Y):(X))using namespace std;int main(){ //freopen("UVa12545.in","r"... 阅读全文
posted @ 2017-04-03 09:47 gwj1139177410 阅读(94) 评论(0) 推荐(0)

1
选择