USACO竞赛12月月赛青铜|白银|黄金组别考情分析~USACO竞赛冲刺班招生中~

时间:2024-09-11 11:55:49  作者:网络 来源:网络
 
12月USACO竞赛青铜组解析
 

 

01
Candy Cane Feast

农夫约翰的奶牛很爱吃甜食,它们特别喜欢吃甘蔗糖!FJ有N头牛,每头牛都有一定的初始身高,他想喂它们M每根也有不同高度(1≤N,M≤2·10^5)。

 

按照它们在输入中的顺序,FJ计划将甘蔗糖一根接一根地喂给奶牛。为了给奶牛喂甘蔗糖,他会把甘蔗糖挂起来,这样甘蔗糖一开始就刚好碰到地面。然后,奶牛将按照输入的顺序一头接一头地排队,走到甘蔗糖前,每头牛都吃到自己的高度(因为它们不能再高了)。即使在奶牛吃掉糖果棒的底部后,糖果棒也会悬挂在最初设置的位置,不会下降到地面。

 

如果甘蔗的底部已经超过奶牛的高度,那么奶牛在轮到它的时候可能什么都不吃。轮到每头牛后,奶牛的身高会根据它们吃了多少单位的甘蔗糖而增加,农民约翰挂上下一根甘蔗糖,奶牛再次重复这个过程(第一头牛再次成为第一个开始吃下一根拐杖糖的人)。

 

试题解析:

这个题是个有意思的暴力问题,同学们考虑一个子问题:

一个数初始是1,每一次操作是让它乘2,要求这个数小于等于n,求最多能操作多少次

这个问题的答案比较显然是log2n次

那考虑当前的问题,考虑第一头牛,如果牛比甘蔗矮,那么它吃完甘蔗后高度乘22;如果牛比甘蔗高,此轮吃甘蔗结束。

所以这一题直接暴力模拟做到甘蔗被吃完复杂度就是对的。

时间复杂度:O(nlog2n)

知识点:暴力,时间复杂度分析

 

02
Cowntact Tracing2

农夫约翰有N排成一行的奶牛(1≤N≤3·10^5)。不幸的是,有一种疾病正在蔓延。

最初,一些奶牛开始被感染。每天晚上,受感染的奶牛都会将疾病传播给左右两侧的奶牛(如果存在的话)。一旦奶牛被感染,它就会继续被感染。

经过几个晚上,农夫约翰意识到问题已经失控,所以他对奶牛进行了测试,以确定谁生病了。找出可能开始患病的奶牛的最小数量。

 

试题解析:

首先我们可以根据输入计算出1的扩散时间最长是多少(时间越长需要的初始点就越少)

注意边界和中间的计算方式不同,中间扩散的结果是1,3,5,...,2*n-1,而边界是1,2,3,...,n$因为边界可以放在最角落开始)

计算出最长扩散时间max_time后我们就可以对每一段连续为1计算初始最少需要放几个1 : len = 2*max_time+1 (len代表连续1个数)

最终将答案相加即可

时间复杂度:O(n)

知识点:贪心,边界条件判断

03
Farmer John Actually Farms

农民约翰正在种植N(1≤N≤2·10^5)他的农场里种着芦笋!然而,他的一些植物有遗传差异,所以有些植物会比其他植物生长得更快。

i的初始高度

第th株是hi英寸,每天之后

第th种植物生长ai英寸。

FJ比其他植物更喜欢他的一些植物,他希望一些特定的植物比其他植物高。他给你一组不同的值t1,…,tN包含0中的所有整数至N−1

他想要我第th株植物正好有ti其他比它高植物。

找到最小天数,以便FJ的要求得到满足,或者确定这是不可能的。

 

试题解析

考虑根据最终的排序结果来确定有多少条件,容易发现其实只有$n-1$个有效的不等式,即第1个小于第2个,第2个小于第3个,...

根据不等式origin_score[i]+increase[i]*t =origin_score[j]+increase[j]*t可以解出t对应的范围

最终对于所有不等式结果求出交集,如果不为空就输出最小值,否则输出-1

时间复杂度:O(n)

知识点:简单数学

可加微信X-NEW0601或长按下方二维码添加

详细咨询

图片

 
12月USACO竞赛黄金组解析
 

 

01
 
P1 Flight Routes
 
 

Bessie recently discovered that her favorite pop artist, Elsie Swift, is performing in her new Eras Tour! Unfortunately, tickets are selling out fast, so Bessie is thinking of flying to another city to attend the concert. The Eras tour is happening in N(2≤N≤750) cities labelled 1…N, and for each pair of cities (i,j) with i<j there either exists a single direct flight from i to j or not.

A flight route from city a to city b (a<b) is a sequence of k≥2 cities a=c1<c2<⋯<ck=b such that for each 1≤i<k, there is a direct flight from city ci to city ci+1. For every pair of cities (i,j) with i<j, you are given the parity of the number of flight routes between them (0 for even, 1 for odd).

While planning her travel itinerary, Bessie got distracted and now wants to know how many pairs of cities have direct flights between them. It can be shown that the answer is uniquely determined.

 

考情分析

从相邻位置来考虑比较简单,如果i到i+1路径为奇数,说明i到i+1有边,反之没有。

考虑任意点i和j的时候,只需要利用区间dp的思想计算出i到j除了直接到达的路径有多少条,看一下是否满足奇偶性即可。

时间复杂度:   O(n^3)

知识点:区间dp

 
 

 

02
 
P2 inimum Longest Trip
 
 

Bessie is going on a trip in Cowland, which has N (2≤N≤2⋅10^5) towns numbered from 1 to N and M (1≤M≤4⋅10^5) one-way roads. The i-th road runs from town ai to town bi and has label li 

(1≤ai,bi≤N, 1≤li≤10^9).

A trip of length k starting at town x0 is a sequence of towns x0,x1,…,xk, such that there is a road from town xi to town xi+1 for all 0≤i<k. It is guaranteed that there are no trips of infinite length in Cowland, and that no two roads connect the same pair of towns.

For each town, Bessie wants to know the longest possible trip starting at it. For some starting towns, there are multiple longest trips - out of these, she prefers the trip with the lexicographically minimum sequence of road labels. A sequence is lexicographically smaller than another sequence of the same length if, at the first position in which they differ, the first sequence has a smaller element than the second sequence.

Output the length and sum of road labels of Bessie's preferred trip starting at each town.

 

考情分析

首先题目保证给出图是DAG,那么我们要求最长路的话就可以利用拓扑排序/bfs来解决。

难点在于题目要求字典序最小,考虑如何快速比较两条出边的字典序大小

由于题目权值可以相同暴力走下去比较时间复杂度会被卡到$O(n^2)$

为了优化比较过程,我们希望能够快速得到两个最长路相同的点他们之间的字典序关系。

所以我们可以动态地对最长路相同的点的内部做一个排序,比较的时候就只需要拿出之前维护好的排序结果去做判断,判断时间复杂度就可以做到O(1)

总时间复杂度:O(nlogn)

知识点:拓扑排序,字典序

 
 

 

03
 
P3 Haybale Distribution
 
 

Farmer John is distributing haybales across the farm!

Farmer John's farm has N (1≤N≤2⋅10^5) barns, located at integer points x1,…,xN (0≤xi≤10^6) on the number line. Farmer John's plan is to first have N shipments of haybales delivered to some integer point y (0≤y≤10^6) and then distribute one shipment to each barn.

Unfortunately, Farmer John's distribution service is very wasteful. In particular, for some ai and bi

(1≤ai,bi≤10^6), ai haybales are wasted per unit of distance left each shipment is transported, and bi haybales are wasted per unit of distance right each shipment is transported. Formally, for a shipment being transported from point y to a barn at point x, the number of haybales wasted is given by

Given Q (1≤Q≤2⋅10^5) independent queries each consisting of possible values of (ai,bi), please help Farmer John determine the fewest amount of haybales that will be wasted if he chooses y optimally.

 

考情分析

观察1:查询的次数很多,可以考虑预处理,由于不需要频繁修改区间,使用前缀和即可。

观察2:题目保证数轴x1...xN上存在一个极小值点y,通过等式变形/反证法可以证明y必定为x1...xN中的一点,同时路径总和f(y)是一个两边往中间递减的单峰函数,可以使用三分法快速逼近y的最优值,三分法模板。

时间复杂度: O(Tlogn)

知识点:三分 

关键字:USACO竞赛,USACO培训班,USACO竞赛辅导,

推荐资讯
Contact Us