P2212 [USACO14MAR]浇地Watering the Fields 题目描述 Due to a lack of rain, Farmer John wants to build an irrigation system to send water between his N fields (1 <= N <= 2000). Each field i is described by a distinct point (xi, yi) in the 2D plane, with 0 &…
P2212 [USACO14MAR]浇地Watering the Fields 题目描述 Due to a lack of rain, Farmer John wants to build an irrigation system to send water between his N fields (1 <= N <= 2000). Each field i is described by a distinct point (xi, yi) in the 2D plane, with 0 &…
传送门 题解:计算欧几里得距离,Krusal加入边权大于等于c的边,统计最后树的边权和. 代码: #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define maxn 2009 using namespace std; int n,c,cnt,tot,ans; int xi[maxn],yi[maxn],fa[maxn]; struct Edge{ int…
一道最小生成树模板题,这里用的Kruskal算法,把每两点就加一条边,跑一遍最小生成树即可. #include <bits/stdc++.h> using namespace std; struct node{ int l , r , w; }; node e[4000010]; int n , maxx , tot , now , ans; int fa[2010] , a[2010] , b[2010]; int find(int x){ if(x == fa[x]) return x;…
https://www.luogu.org/problem/show?pid=2115 题目描述 Farmer John's arch-nemesis, Farmer Paul, has decided to sabotage Farmer John's milking equipment! The milking equipment consists of a row of N (3 <= N <= 100,000) milking machines, where the ith machi…
[题解] 每个格子可以到达的区域是一个菱形,但是我们并不能快速的求和,所以我们可以把原来的草地旋转45度,用二维前缀和快速处理菱形的区域的和. #include<cstdio> #include<cstring> #include<algorithm> #define LL long long #define N 1000 #define rg register using namespace std; int n,m,k,a[N][N]; LL s[N][N],ans…
题目描述 Farmer John's arch-nemesis, Farmer Paul, has decided to sabotage Farmer John's milking equipment! The milking equipment consists of a row of N (3 <= N <= 100,000) milking machines, where the ith machine produces M_i units of milk (1 <= M_i &…
题面 一道思维难度不大的状态压缩,也并不卡常,但细节处理要格外注意: f[i][j]表示前i行最后一行状态是j的方案数 #include <bits/stdc++.h> #define p 100000000 using namespace std; int n,m; ][]; ]; ][]; int main() { cin>>n>>m; ;i<=n;i++){ ;j<=m;j++){ scanf("%d",&a[i][j]);…
题目の传送门:https://www.luogu.org/problem/show?pid=1550 精简版题意(本来就精简了不是么):n个点,每个点可以选择打井或从别的有水的点引水,求所有点都有水用的最小费用.(我是不是一说反而更不懂了) 这题其实并不是很难,讲道理贪心都能过.. 令我感到有趣的是这题中一种非常神奇的解题思路.. 首先,如果这个题没有打井的选项,显然是最小生成树 然而我们现在要打井,就不能直接用最小生成树做了.. 殊不知,这题还是一个最小生成树~ 这就需要一些小小的.巧妙的办法…
P2212 [USACO14MAR]浇地Watering the Fields 题目描述 Due to a lack of rain, Farmer John wants to build an irrigation system to send water between his N fields (1 <= N <= 2000). Each field i is described by a distinct point (xi, yi) in the 2D plane, with 0 &…