【洛谷P1948】[USACO08JAN]电话线】的更多相关文章

P1948 [USACO08JAN]电话线Telephone Lines 题目描述 Farmer John wants to set up a telephone line at his farm. Unfortunately, the phone company is uncooperative, so he needs to pay for some of the cables required to connect his farm to the phone system. There a…
P1948 [USACO08JAN]电话线Telephone Lines 题目描述 Farmer John wants to set up a telephone line at his farm. Unfortunately, the phone company is uncooperative, so he needs to pay for some of the cables required to connect his farm to the phone system. There a…
目录 题面 题目链接 题目描述 输入输出格式 输入格式 输出格式 输入输出样例 输入样例 输出样例 说明 思路 AC代码 题面 题目链接 P1948 [USACO08JAN]电话线Telephone Lines 题目描述 Farmer John wants to set up a telephone line at his farm. Unfortunately, the phone company is uncooperative, so he needs to pay for some of…
题目描述 Farmer John wants to set up a telephone line at his farm. Unfortunately, the phone company is uncooperative, so he needs to pay for some of the cables required to connect his farm to the phone system. There are N (1 ≤ N ≤ 1,000) forlorn telephon…
P1948 [USACO08JAN]电话线Telephone Lines 题意 题目描述 Farmer John wants to set up a telephone line at his farm. Unfortunately, the phone company is uncooperative, so he needs to pay for some of the cables required to connect his farm to the phone system. Ther…
电话线 题目链接:https://www.luogu.org/problemnew/show/P1948 二分答案+最短路 我们要求一条1~n的路径,使其中的第k+1大的数最小. 二分第k+1大的数的大小h,比h小的边可以看为0,因为它们不会让第k+1大的数更大:比h大的边边权设为1,最后求出的1~n的最短路,就是在第k+1大的数小于等于h时需要让电信公司承担的电话线数,因为在第k+1大的数的大小限制为h的情况下,任何比h大的数都不可以自己承担.若dis[n]>k返回false,否则返回true…
题面 题解 很显然,答案满足单调性. 因此,可以使用二分答案求解. 考虑\(check\)的实现. 贪心地想,免费的\(k\)对电话线一定都要用上. 每次\(check\)时将小于\(mid\)的边权设为\(0\),其它的设为\(1\). 跑一边最短路判断\(\mathrm{dist[n]}\)是否\(\leq k\)即可. 代码 #include <bits/stdc++.h> #define itn int #define gI gi using namespace std; inline…
这道题其实是分层图,但和裸的分层图不太一样.因为它只要求路径总权值为路径上最大一条路径的权值,但仔细考虑,这同时也满足一个贪心的性质,那就是当你每次用路径总权值小的方案来更新,那么可以保证新的路径权值尽量小. 所以这道题在不删边的情况下可以使用Dij来跑,而删边权的情况就是分层图. 所以就拿分层图来搞好了^_^. 由于这个数据p和k都比较大,所以直接建k+1层图是要爆的,而k+1层图边都一样,我们就用dis[层数(0-k)]来表示. 具体的就是每次Dij转移是要分两种情况: 1.在原层跑,也就是…
二分答案 首先,最大值最小,就是二分答案 #include <iostream> #include <cstdio> #include <algorithm> #include <cmath> #include <cstdlib> #include <cstring> #include <queue> using namespace std; const int MAXN = 10005; int head[MAXN],…
[USACO08JAN]haybale猜测Haybale Guessing 题目描述 给一段长度为\(n\),每个位置上的数都不同的序列\(a[1\dots n]\)和\(q\)和问答,每个问答是\((x, y, r)\)代表\(\min_\limits{i=a}^ba_i= r\), 要你给出最早的有矛盾的那个问答的编号. 输入输出格式 输入格式: Line 1: Two space-separated integers: \(N\) and \(Q\) Lines 2..\(Q+1\): E…