
贪心
CCSUZB
吾生也有涯,而知也无涯
展开
-
Uva714
二分加贪心这道题可以自己预先设置一个x 使得所有的是S(i) 均小于这个x 而x的求法可以通过二分法求得 最后贪心输出解#include <iostream> #include <cstring> #include <algorithm> using namespace std;const int maxn = 600; int n, m, k,maxp; long long tot; int原创 2017-07-04 10:04:19 · 326 阅读 · 0 评论 -
选择不相交区间
贪心思想根据每个区间的结束点进行排序,然后进行更新#include <iostream> #include <algorithm> using namespace std;struct Point { int x, y; bool operator<(const Point s) const { return y < s.y; } }A[1002];原创 2017-06-25 21:18:19 · 267 阅读 · 0 评论 -
Parenthesis
2016湖南省第G题 题目链接在知乎上看了叉姐的题解后还是没懂说是贪心法 后来明白只有交换前者‘(’和后者‘)’ 因为这样的交换会导致前面的左括号‘(’减少 而要使得交换后括号匹配就必须使得交换区间[a,b)内的左括号数量减去右括号数量大于2 (l[i] - r[i] <= 1)//在中南大学评测机上用cin cout会超时 菜鸡再也不用了#include <iostream> #include原创 2017-07-05 14:04:55 · 383 阅读 · 0 评论 -
ZOJ 3953-贪心
题目链接对区间的左端点进行排序,然后每三个点进行一次判断,如果出现两两相交的情况就删除右端点值最大的那个区间#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include <string> #include <string.h> #include <cmath> #include <ss原创 2017-08-16 10:54:46 · 265 阅读 · 0 评论