P2202 [USACO13JAN]方块重叠Square Overlap 题目描述 Farmer John is planning to build N (2 <= N <= 50,000) square fenced-in pastures on his farm, each of size exactly K x K (1 <= K <= 1,000,000). Pasture i is centered at point (x_i, y_i) with integer coo…
P3068 [USACO13JAN]派对邀请函Party Invitations 题目描述 Farmer John is throwing a party and wants to invite some of his cows to show them how much he cares about his herd. However, he also wants to invite the smallest possible number of cows, remembering all t…
P3068 [USACO13JAN]派对邀请函Party Invitations 题目描述 Farmer John is throwing a party and wants to invite some of his cows to show them how much he cares about his herd. However, he also wants to invite the smallest possible number of cows, remembering all t…
P3070 [USACO13JAN]岛游记Island Travels 题目描述 Farmer John has taken the cows to a vacation out on the ocean! The cows are living on N (1 <= N <= 15) islands, which are located on an R x C grid (1 <= R, C <= 50). An island is a maximal connected gro…
P3071 [USACO13JAN]座位Seating 题目描述 To earn some extra money, the cows have opened a restaurant in their barn specializing in milkshakes. The restaurant has N seats (1 <= N <= 500,000) in a row. Initially, they are all empty. Throughout the day, there…
P3071 [USACO13JAN]座位Seating 题目链接 思路: 一开始把题给读错了浪费了好多时间呜呜呜. 因为第二个撤离操作是区间修改,所以我们可以想到用线段树来做.对于第一个操作,我们只需要维护suml,sumr,sum分别表示当前结点左端连续有多少个空位.右端连续有多少个空位.以及最长连续空位为多少就行了.因为每次安排作为可能会跨过mid,所以我们还需要数组来维护一下信息. 注意一下代码的细节吧: #include <bits/stdc++.h> using namespace…
传送门 题目大意: 开始站在原点,给出一系列操作 x L/R,表示向左或向右走几步. 最多会移动到离原点1,000,000,000单位远的地方. n次操作,n<=100000 问走过k次的地方有几个 题解:离散化+差分 看了官方题解,很明白. 发现n<=100000,看出所到达的不同的点最多只有100001个 这个是可以用数组存的,用到了坐标压缩的思想,很重要. pos[i]表示第i次走的点的位置. C[]是差分数组. 代码: #include<iostream> #include…
这题其实没什么,但用到的算法都十分有用.做一个不恰当的比喻,这是一只必须用牛刀杀的鸡,但因为我这个蒟蒻杀不死牛,所以只能找只鸡来练练手. 题目描述 Farmer John 想出了一个给牛棚旁的长围墙涂色的好方法.(为了简单起见,我们把围墙看做一维的数轴,每一个单位长度代表一块栅栏)他只是简单的把刷子蘸满颜料,系在他最喜欢的奶牛Bessie上,然后让Bessie来回地经过围墙,自己则在一旁喝一杯冰镇的凉水.(……-_-|||) Bessie 经过的所有围墙都会被涂上一层颜料.Bessie从围墙上的…
题目描述 Farmer John has devised a brilliant method to paint the long fence next to his barn (think of the fence as a one-dimensional number line). He simply attaches a paint brush to his favorite cow Bessie, and then retires to drink a cold glass of wat…
思路 考虑比较朴素的解法,枚举每个长度为\(k+1\)的区间,然后统计区间中出现次数最多的颜色.这样的话复杂度为\(O(n*k)\)的,显然不行. 观察到统计每个区间中出现次数最多的颜色中,可以只用看每种颜色在区间中出现的最后一个位置,这样的话只需要我们开个桶统计一下数量就行. 所以就类似于尺取那样,维护颜色种类不超过\(k+1\)的区间,对于每次新加进来的值令其\(cnt++\),并且维护ans.当颜色种类超过\(k+1\)时,就减去区间前面的值,因为它们与后面的颜色不可能再连在一起了. 因为…