[题解] 每个格子可以到达的区域是一个菱形,但是我们并不能快速的求和,所以我们可以把原来的草地旋转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…
P2213 [USACO14MAR]懒惰的牛The Lazy Cow_Sliver 最大化一个子矩阵的和. 我们如何去做,dp和贪心呀! 大体题意:给定一个正方形,然后在正方形中求出一个大小已经给定的倾斜45的子正方形.使得这个正方形内的元素和最大. 倾斜45度? 好像可以做,有点麻烦? 可以观察到,如果我们将一个已经计算好了的菱形进行平推一格,那么变动的元素只\(2\ast k-1\)(k为边长).然后每次维护就可以了. 时间复杂度\(O(n^2k)\) 感觉是对的.可我就是不愿意写.那怎么办…
HAOI2006 (洛谷P2341)受欢迎的牛 题解 题目描述 友情链接原题 每头奶牛都梦想成为牛棚里的明星.被所有奶牛喜欢的奶牛就是一头明星奶牛.所有奶 牛都是自恋狂,每头奶牛总是喜欢自己的.奶牛之间的"喜欢"是可以传递的--如果A喜 欢B,B喜欢C,那么A也喜欢C.牛栏里共有N 头奶牛,给定一些奶牛之间的爱慕关系,请你 算出有多少头奶牛可以当明星. 输入输出格式 输入格式: 第一行:两个用空格分开的整数:N和M 第二行到第M + 1行:每行两个用空格分开的整数:A和B,表示A喜欢B…
传送门啦 这是一个tarjan强连通分量与出度结合的例题. 先明确一下题意,如果这个点(缩点之后的)没有出度,这个点才能成为明星牛(明星牛的定义是:所有牛都喜欢他才可以). 由于我们进行了缩点,所以我就另外开一个数组num[i]:表示这个强连通分量中有多少个点. int sum = 0; for(int i=1;i<=cnt;i++) if(!chu[i]) ans = num[i] , sum++; if(sum >= 2) printf("0"); else print…
P2990 [USACO10OPEN]牛跳房子Cow Hopscotch 题目描述 The cows have reverted to their childhood and are playing a game similar to human hopscotch. Their hopscotch game features a line of N (3 <= N <= 250,000) squares conveniently labeled 1..N that are chalked o…
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 &…
P3047 [USACO12FEB]附近的牛Nearby Cows 题目描述 Farmer John has noticed that his cows often move between nearby fields. Taking this into account, he wants to plant enough grass in each of his fields not only for the cows situated initially in that field, but…
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 &…
题意 题目链接 Sol 显然如果题目什么都不说的话需要\(\frac{n * (n - 1)}{2}\)个相对关系 然后求一下传递闭包减掉就行了 #include<bits/stdc++.h> using namespace std; const int MAXN = 1001; inline int read() { char c = getchar(); int x = 0, f = 1; while(c < '0' || c > '9') {if(c == '-') f =…
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…