题目の传送门:https://www.luogu.org/problem/show?pid=1550 精简版题意(本来就精简了不是么):n个点,每个点可以选择打井或从别的有水的点引水,求所有点都有水用的最小费用.(我是不是一说反而更不懂了) 这题其实并不是很难,讲道理贪心都能过.. 令我感到有趣的是这题中一种非常神奇的解题思路.. 首先,如果这个题没有打井的选项,显然是最小生成树 然而我们现在要打井,就不能直接用最小生成树做了.. 殊不知,这题还是一个最小生成树~ 这就需要一些小小的.巧妙的办法…
洛谷题目传送门 闲话 看完洛谷larryzhong巨佬的题解,蒟蒻一脸懵逼 如果哪年NOI(放心我这样的蒟蒻是去不了的)又来个决策单调性优化DP,那蒟蒻是不是会看都看不出来直接爆\(0\)?! 还是要想点办法,不失一般性也能快捷地判定决策单调. 对于判定决策单调的分析 再补一句决策单调性的概念:状态转移方程形如\(f_i=\min/\max_{j=1}^{i-1} g_j+w_{i,j}\),且记\(f_i\)的最优决策点为\(p_i\)(也就是\(f_i\)从\(g_{p_i}+w_{i,p_…
洛谷P2914:https://www.luogu.org/problemnew/show/P2914 哇 这题目在暑假培训的时候考到 当时用Floyed会T掉 看楼下都是用Dijkstra 难道没有人用优雅的SPFA吗? 思路 用前向星构建整个图 注意每一条边都不能超过len(也就是题目中的m) 所以存图的时候注意一下这一点就行了 其他就跟SPFA一样套板子 代码中还有详细注解 注意坑点:数组开大一点 没开大的我RE了2次 代码 #include<iostream> #include<…
描述 Description 农民约翰被选为他们镇的镇长!他其中一个竞选承诺就是在镇上建立起互联网,并连接到所有的农场.当然,他需要你的帮助.约翰已经给他的农场安排了一条高速的网络线路,他想把这条线路共享给其他农场.为了用最小的消费,他想铺设最短的光纤去连接所有的农场.你将得到一份各农场之间连接费用的列表,你必须找出能连接所有农场并所用光纤最短的方案.每两个农场间的距离不会超过100000 输入格式 Input Format 第一行: 农场的个数,N(3<=N<=100). 第二行..结尾:…
题目大意:输入S1,S2,S3,随机生成三个数x,y,z,求x+y+z出现次数最多的数(如果有多个答案输出最小的),其中1<=x<=S1,1<=y<=S2,1<=z<=S3. 数据范围:(2 <= S1 <= 20; 2 <= S2 <= 20; 2 <= S3 <= 40) 由题可知数据范围不大,可以直接暴力,请见代码 /* 浴谷2911 */ #include <iostream> using namespace st…
2021-08-03 20:31:13 链接: https://www.luogu.com.cn/problem/P2212 题目详情: 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) i…
题面 题目背景 John的农场缺水了!!! 题目描述 Farmer John has decided to bring water to his N (1 <= N <= 300) pastures which are conveniently numbered 1..N. He may bring water to a pasture either by building a well in that pasture or connecting the pasture via a pipe…
P1550 [USACO08OCT]打井Watering Hole 题目背景 John的农场缺水了!!! 题目描述 Farmer John has decided to bring water to his N (1 <= N <= 300) pastures which are conveniently numbered 1..N. He may bring water to a pasture either by building a well in that pasture or con…
传送门 题解 决策单调性是个啥……导函数是个啥……这题解讲的是啥……我是个啥…… //minamoto #include<iostream> #include<cstdio> #include<cstring> #include<cmath> #define LD long double #define calc(i,j) f[j]+qpow(abs(s[i]-s[j]-L)) using namespace std; inline int read(){…
题目描述 The N cows (2 <= N <= 1,000) conveniently numbered 1..N are grazing among the N pastures also conveniently numbered 1..N. Most conveniently of all, cow i is grazing in pasture i. Some pairs of pastures are connected by one of N-1 bidirectional…