Problem 3: Threatening Letter [J. Kuipers, 2002] FJ has had a terrible fight with his neighbor and wants to send him a nasty letter, but wants to remain anonymous. As so many before him have done, he plans to cut out printed letters and paste them on…
Problem 1: Cow Calisthenics [Michael Cohen, 2010] Farmer John continues his never-ending quest to keep the cows fit by having them exercise on various cow paths that run through the pastures. These cow paths can be represented as a set of vertices co…
Link: USACO 2017 Dec Gold 传送门 A: 为了保证复杂度明显是从终结点往回退 结果一开始全在想优化建边$dfs$……其实可以不用建边直接$multiset$找可行边跑$bfs$就行了 由于保证每个点只进队列一次.被搜索到一次,因此复杂度为$O(n*log(n))$ #include <bits/stdc++.h> using namespace std; #define X first #define Y second typedef long long ll; typ…
传送门:http://www.usaco.org/index.php?page=viewproblem2&cpid=93 很容易发现,这是一个二分图的模型.竖直线是X集,水平线是Y集,若某条竖直线与水平线相交,则连边.由于目的是要没有任何两条线相交,所以二分图的边的两端不能同时取,就是要求一个二分图的最大独立集,which equals to N - 最大匹配. 然而啊然而,仍然没有一A!此题只是说给出线段两端点的坐标,并没有说x1一定<x2,y1一定<y2... 可以说这是本次月赛金…
传送门:http://www.usaco.org/index.php?page=viewproblem2&cpid=91 这一题我很快的想出了,把>= x的值改为1,< x的改为-1,这样,某一段连续区间的和若非负,则这段区间符合题意.我连这个都想到了却没想到要去求逆序对!!!天呐,我真是太迷了!! 前缀和+逆序对. 逆序对就不解释了,该归并的归并,Fenwick Tree的Fenwick Tree,但是对于此题有一个O(n)的算法,仅限于求此题的逆序对!鉴于这一题值域范围小,而且相邻…
和上一题(POJ1743,上一篇博客)相似,只是二分的判断条件是:是否存在一段后缀的个数不小于k #include <iostream> #include <algorithm> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <ctime> #include <map> using namesp…
/*codevs 3279 二分+dfs贪心检验 堆版本 re一个 爆栈了*/ #include<cstdio> #include<queue> #include<cstring> #define pa pair<int,int> #define mk make_pair #define X first #define Y second #define maxn 100010 using namespace std; int n,S,num,head[max…
题目描述 跟所有人一样,农夫约翰以着宁教我负天下牛,休叫天下牛负我的伟大精神,日日夜夜苦思生 财之道.为了发财,他设置了一系列的规章制度,使得任何一只奶牛在农场中的道路行走,都 要向农夫约翰上交过路费. 农场中由N(1 <= N <= 250)片草地(标号为1到N),并且有M(1 <= M <= 10000)条 双向道路连接草地A_j和B_j(1 <= A_j <= N; 1 <= B_j <= N).奶牛们从任意一片草 地出发可以抵达任意一片的草地.FJ已…
题目描述 输入 * 第1行: 两个由空格隔开的整数: N和V * 第2到第N+1行: 第i+1行表示第i种游戏平台的价格和可以在这种游戏平台上面运行的游 戏.包含: P_i, G_i还有G_i对由空格隔开的整数GP_j, PV_j 输出 * 第1行: 农夫约翰在预算内可以得到的最大的产出值. 样例输入 3 800 300 2 30 50 25 80 600 1 50 130 400 3 40 70 30 40 35 60 样例输出 210   一看到这题第一感觉就是背包,这题确实就是背包,只不过…
Link: 传送门 A: 贪心从小到大插入,用并查集维护连通性 #include <bits/stdc++.h> using namespace std; #define X first #define Y second typedef double db; typedef long long ll; typedef pair<int,int> P; ; int n,tot,cnt,f[MAXN];P dat[MAXN]; struct edge{int x,y;ll w;}e[M…