P2873 [USACO07DEC]泥水坑Mud Puddles 题目描述 Farmer John is leaving his house promptly at 6 AM for his daily milking of Bessie. However, the previous evening saw a heavy rain, and the fields are quite muddy. FJ starts at the point (0, 0) in the coordinate p…
P2873 [USACO07DEC]泥水坑Mud Puddles bfs入门. 对于坐标为负的情况,我们可以给数组下标加上$abs(min(minx,miny))$转正(根据题意判断) #include<iostream> #include<cstdio> #include<cstring> #include<queue> #define re register using namespace std; #define M 502 ]={,,,-}; ]={…
题目描述 Farmer John is leaving his house promptly at 6 AM for his daily milking of Bessie. However, the previous evening saw a heavy rain, and the fields are quite muddy. FJ starts at the point (0, 0) in the coordinate plane and heads toward Bessie who…
一道\(0/1\)分数规划+负环 POJ原题链接 洛谷原题链接 显然是\(0/1\)分数规划问题. 二分答案,设二分值为\(mid\). 然后对二分进行判断,我们建立新图,没有点权,设当前有向边为\(z=(x,y)\),\(time\)为原边权,\(fun\)为原点权,则将该边权换成\(mid\times time[z]+fun[x]\),然后在上面跑\(SPFA\). 如果有一个环使得\(\sum\{mid\times time[z]+fun[x]\}<0\),则说明\(mid\)小了,而式子…
P2868 [USACO07DEC]观光奶牛Sightseeing Cows 题目描述 Farmer John has decided to reward his cows for their hard work by taking them on a tour of the big city! The cows must decide how best to spend their free time. Fortunately, they have a detailed city map sh…
Portal Description 给出一个字符串\(s(|s|\leq3\times10^4)\),每次从\(s\)的开头或结尾取出一个字符接在新字符串\(s'\)的末尾.求字典序最小的\(s'\). Solution 设当前剩余的字符串为\(t\),将其翻转得到\(t'\).则\(t<t'\)时取开头,否则取结尾. 令\(p=lcp(t,t')\),则有\(t<t' \Leftrightarrow t[1..p]=t'[1..p],t[p+1]<t'[p+1]\).那么最优的取法必…
P2872 [USACO07DEC]道路建设Building Roads 题目描述 Farmer John had just acquired several new farms! He wants to connect the farms with roads so that he can travel from any farm to any other farm via a sequence of roads; roads already connect some of the farms…
P2872 [USACO07DEC]道路建设Building Roads 题目描述 Farmer John had just acquired several new farms! He wants to connect the farms with roads so that he can travel from any farm to any other farm via a sequence of roads; roads already connect some of the farms…
题意 题目链接 Sol 复习一下01分数规划 设\(a_i\)为点权,\(b_i\)为边权,我们要最大化\(\sum \frac{a_i}{b_i}\).可以二分一个答案\(k\),我们需要检查\(\sum \frac{a_i}{b_i} \geqslant k\)是否合法,移向之后变为\(\sum_{a_i} - k\sum_{b_i} \geqslant 0\).把\(k * b_i\)加在出发点的点权上检查一下有没有负环就行了 #include<bits/stdc++.h> #defin…
题目传送门 这道题明显就是个01背包.所以直接套模板就好啦. #include<bits/stdc++.h> #define MAXN 30000 using namespace std; int f[MAXN],w[MAXN],c[MAXN],n,v; int main(){ scanf("%d%d",&n,&v); ;i<=n;i++) scanf("%d%d",&w[i],&c[i]); ;i<=n;i+…