
贪心
一只会旅行的猫
这个作者很懒,什么都没留下…
展开
-
田忌赛马
分析:反正就是让1)A的好马>B好马,win 2)A的慢马>B的慢马,lost 3)1、2条件都不满足时,用A的慢马->B的好马,平局不管,否则lost #include #include #include using namespace std; const int N=1005; int a[N],b[N]; bool comp(int A,int B) { if(A>B) ret原创 2013-06-15 23:55:29 · 678 阅读 · 0 评论 -
hdu 2600 War
http://acm.hdu.edu.cn/showproblem.php?pid=2600 题意:要求找出不发生战争的最后一年 分析:按照x,y都最大排序,即:从最大的区间开始查找战争年间是否有断层 #include #include #include using namespace std; struct War{ int x,y; }war[105];原创 2013-10-19 11:07:40 · 682 阅读 · 0 评论 -
hdu 1264 Counting Squares
http://acm.hdu.edu.cn/showproblem.php?pid=1264 分析:以左下角的点标志每个小正方形数过, #include #include using namespace std; int a[105][105]; int main() { int x1,x2,y1,y2,rx,ry,i,j,ans; memset(a,0,原创 2013-10-19 10:48:27 · 529 阅读 · 0 评论 -
hdu 4004 The Frog's Games
http://acm.hdu.edu.cn/showproblem.php?pid=4004 分析:二分查找+贪心(哎) #include #include #include using namespace std; const int NM=500005; int a[NM],n,m; bool Stone(int mid) { int k,t,i,j; i=1;j=k=原创 2013-08-22 20:17:52 · 549 阅读 · 0 评论 -
hdu 4296 Buildings(外一篇:hdu 4310 Hero)
http://acm.hdu.edu.cn/showproblem.php?pid=42 分析:条件:A.w+A.s 具体分析:http://blog.youkuaiyun.com/acm_ted/article/details/7984935 1) a=sum-si;b=sum+wi-sj; 交换两个板的位置 2)b'=sum-sj;a'=sum+wj-s原创 2013-07-23 22:01:14 · 570 阅读 · 0 评论 -
hdu 1445 Ride to School
http://acm.hdu.edu.cn/showproblem.php?pid=1445 分析:原先把问题想麻烦了,其实只要理清思路就会发现,无论自己的车速会怎么变,最后一定会和一个人同时到达,那么计算这个人的到达时间即可 其中,时间为负数的不用考虑,要么你追不上,要么他追不上你 #include #include #include #include using namespace st原创 2013-07-24 23:14:47 · 712 阅读 · 0 评论 -
hdu 4070 Phage War
http://acm.hdu.edu.cn/showproblem.php?pid=4070 题意:一个噬菌体周围有编号1~n个细胞,每一秒钟这个噬菌体就产生一个新的噬菌体,想要感染细胞需要:1)Di个噬菌体 2)Ti秒的到达时间,问最少需要多少时间可以使所有的细胞都被感染? 分析:先感染需要到达时间最长的细胞,利用剩下时间繁殖噬菌体,然后更新最长时间 #include #include #原创 2013-07-30 16:05:15 · 689 阅读 · 0 评论 -
hdu 3183 A Magic Lamp
http://acm.hdu.edu.cn/showproblem.php?pid=3183 题意:从一个数里删除n个数字,使其最小 分析:只需判断第i个数是否大于第i+1个数,实则删掉,否则继续寻找;注意0的存在,只要第二位数是0,直接删除第一个数即可,因为数的位数减少了 #include #include #include #include #include using namespac原创 2013-07-30 20:08:02 · 550 阅读 · 0 评论 -
hdu 1051 Wooden Sticks
分析:排序后,从小找到大,注意保存第一个不满足条件的stick,作为第二次查找的开始 #include #include using namespace std; const int NM=5005; struct Stick{ int x,y; }st[NM]; bool comp(struct Stick A,struct Stick B) { if(A.x<B.x) retur原创 2013-07-13 11:14:48 · 520 阅读 · 0 评论 -
nyoj 6 喷水装置(一)
分析:想要完整覆盖,需要两个圆相交,得到有效的距离为下图中红线段,即:x=sqrt(r*r-1*1) #include #include #include #include #include using namespace std; const int NUM=605; double a[NUM]; bool comp(double A,double B) { if(A>B原创 2013-06-16 19:25:20 · 820 阅读 · 0 评论 -
第四章 贪心算法
4.1 活动安排问题 分析:按照结束时间非递减排序,再贪心。 #include #include #include #include using namespace std; const int NM=105; bool x[NM]; struct Node{ int s,f; }q[NM]; bool comp(struct Node A,struct Node B){ re原创 2014-04-03 11:48:07 · 531 阅读 · 0 评论