第二章
题解
天才夏洛克
这个作者很懒,什么都没留下…
展开
-
poj2386 Lake Counting
dfs的简单应用,求数组连通块 #include <cstdio> #include <iostream> #include <cstring> #include <cmath> #include <vector> #include <set> #include <string> #include <map> #include <stack> #include <queue> #inclu原创 2021-05-19 10:10:31 · 36 阅读 · 0 评论 -
P6140 [USACO07NOV]Best Cow Line S
难度:4 贪心问题,贪心策略要想对,这种一般都是从字典序全局考虑的,不能值考虑单独一个点, #include <bits/stdc++.h> #define fi first #define se second #define pb push_back #define all(x) (x).begin(), (x).end() using namespace std; typedef long long ll; typedef vector<int> vi; typedef p原创 2021-06-01 13:53:59 · 68 阅读 · 0 评论 -
poj3069 Saruman‘s Army
贪心题,首先把题意读懂,然后就是操作,先找当前未被包含在内点,然后去找它右边最远的范围内的点,模拟写好即可, #include <cstdio> #include <iostream> #include <cstring> #include <cmath> #include <vector> #include <set> #include <string> #include <map> #include <原创 2021-06-01 16:23:32 · 60 阅读 · 0 评论 -
P1090 [NOIP2004 提高组] 合并果子 / [USACO06NOV] Fence Repair G
难度:3 用优先队列很好做,书上的n方的做法没有看。 #include <bits/stdc++.h> #define fi first #define se second #define pb push_back #define all(x) (x).begin(), (x).end() using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int, int>原创 2021-06-01 16:28:48 · 133 阅读 · 0 评论 -
poj1979 Red and Black
dfs求连通块,输入的时候注意是先输入列数再输入行数。 #include <cstdio> #include <iostream> #include <cstring> #include <cmath> #include <vector> #include <set> #include <string> #include <map> #include <stack> #include <queu原创 2021-05-20 19:29:32 · 34 阅读 · 0 评论 -
P2895 Meteor Shower S
难度:3 这道题poj上面也有啊,看来都不是洛谷或者poj首发的, 题意,0到300会在某时刻受到陨石的攻击,输出啥时候能到安全位置,不能则是-1, 思路,输入的时候先整理每个点的被毁坏时间,取最小的那个,这里为了方便方向数组写成了5个大小的,把中间的也包含进去,然后就是bfs判断,入队之前就要判断是不是这个点已经被毁坏了,也就是是不是变成障碍物不能走了, 然后有一个很坑的地方,彗星撞击的区域是0到300,而人能走的是0到无穷,也就是只要你能走到302,立马就安全了,你要么不能走到安全的位置,要么安全位置小原创 2021-05-21 11:07:19 · 104 阅读 · 0 评论 -
poj2376 Cleaning Shifts
区间贪心,用最少的线段覆盖的问题,首先要知道求解的过程中区间可能连不上,这就会输出-1,然后就是要想明白什么时候要退出循环, #include <cstdio> #include <iostream> #include <cstring> #include <cmath> #include <vector> #include <set> #include <string> #include <map> #incl原创 2021-06-17 15:29:12 · 52 阅读 · 0 评论 -
P1376 [USACO05MAR]Yogurt factory 机器工厂
难度:2 一道比较简单的贪心题,最后的结果有一个应该是超int了,所以把能换的全换成longlong了, #include <bits/stdc++.h> #define fi first #define se second #define pb push_back #define all(x) (x).begin(), (x).end() using namespace std; typedef long long ll; typedef vector<int> vi; ty原创 2021-06-01 20:18:10 · 81 阅读 · 0 评论 -
UVA311 Packets
难度:5 一道贪心,而且我感觉很多贪心问题自带模拟性质,看了一眼别人的题解貌似有很简单的写法,我这个就比较麻烦了,一步一步考虑,6个的不用说,5的完了之后1的数量减去11,4也是直接加,然后先去考虑2的数量,分两种情况,除去2之后可以看看去减去1,然后是3,这个是最麻烦的,因为如果不能整除,里面有剩余3空间数量为123,三种情况,分别考虑,策略都是先看2的数量,优先减去2的数量,如果还有空位,那么就减去1的数量,这个过程之中,2的数量是有下界的,就是0,因为2为0之后就要考虑1了,所以不会出现负数,而1不同原创 2021-06-02 15:57:00 · 44 阅读 · 0 评论 -
poj1862 Stripies
比较简单的贪心题,和霍夫曼编码类似, #include <cstdio> #include <iostream> #include <cstring> #include <cmath> #include <vector> #include <set> #include <string> #include <map> #include <stack> #include <queue> #in原创 2021-06-17 15:57:00 · 51 阅读 · 0 评论 -
P2878 [USACO07JAN]Protecting the Flowers S
难度:3 主要就是分析贪心的策略,这个好像就是用到了邻项分析的方法,设两个例子,相邻的,然后看哪个排前面消耗少,哪个就排前面,排序的依据就是这里来的, #include <bits/stdc++.h> #define fi first #define se second #define pb push_back #define all(x) (x).begin(), (x).end() using namespace std; typedef long long ll; typedef v原创 2021-06-01 20:49:17 · 61 阅读 · 0 评论