2024年12月USACO竞赛银奖组问题二—Deforestation

Farmer John is expanding his farm! He has identified the perfect location in the Red-Black Forest, which consists of N trees (1≤N≤105  ) on a number line, with the i-th tree at position xi (−109≤xi ≤109).

Environmental protection laws restrict which trees Farmer John can cut down to make space for his farm. There are K restrictions (1≤K≤105 ) specifying that there must always be at least ti trees (1≤ti ≤N) in the line segment [li,ri]
, including the endpoints (−109≤liri≤109). It is guaranteed that the Red-Black Forest initially satisfies these restrictions.

Farmer John wants to make his farm as big as possible. Please help him compute the maximum number of trees he can cut down while still satisfying all the restrictions!

INPUT FORMAT (input arrives from the terminal / stdin):

Each input consists of T (1≤T≤10) independent test cases. It is guaranteed that the sums of all N and of all K within an input each do not exceed 3⋅105.

The first line of input contains T. Each test case is then formatted as follows:

The first line contains integers N and K.
The next line contains the N integers x1,…,xN.
Each of the next K lines contains three space-separated integers: li, ri and ti.

OUTPUT FORMAT (print output to the terminal / stdout):

For each test case, output a single line with an integer denoting the maximum number of trees Farmer John can cut down.

SAMPLE INPUT:

3
7 1
8 4 10 1 2 6 7
2 9 3
7 2
8 4 10 1 2 6 7
2 9 3
1 10 1
7 2
8 4 10 1 2 6 7
2 9 3
1 10 4

SAMPLE OUTPUT:

4
4
3

For the first test case, Farmer John can cut down the first 4 trees, leaving trees at

xi = 2,6,7 to satisfy the restriction.

For the second test case, the additional restriction does not affect which trees Farmer John can cut down, so he can cut down the same trees and satisfy both restrictions.

For the third test case, Farmer John can only cut down at most 3 trees because there are initially 7 trees but the second restriction requires him to leave at least 4 trees uncut.

SCORING:

Input 2: N , K≤16
Inputs 3-5: N, K≤1000
Inputs 6-7:ti=1 for all i=1,…,K.
Inputs 8-11: No additional constraints.

Problem credits: Tina Wang, Jiahe Lu, Benjamin Qi

扫码领取USACO试题答案+详细解析

咨询一对一备赛规划

USACO竞赛考试网-二维码

2024年12月USACO竞赛银奖组问题一—Cake Game

Bessie and Elsie have discovered a row of N cakes (2≤N≤5⋅105 ,N even)
cakes, with sizes a1,a2,…,aN in that order (1≤ai≤109).

Each cow wants to eat as much as possible. However, being very civilized cows, they decided to play a game to split it! The game proceeds with both cows alternating turns. Each turn consists of one of the following:

1.Bessie chooses two adjacent cakes and stacks them, creating a new cake with the sum of the sizes.
2.Elsie chooses either the leftmost or rightmost cake and puts it in her stash.

When only one cake remains, Bessie eats it, and Elsie eats all cakes in her stash. If both cows play optimally to maximize the amount of cake they eat and Bessie plays first, how much cake will each cow eat?

INPUT FORMAT (input arrives from the terminal / stdin):

Each input consists of T (1≤T≤10) independent test cases. It is guaranteed that the sum of all N within an input does not exceed 106.

Each test case is formatted as follows. The first line contains N . The next line contains N space-separated integers, a1,a2,…,aN.

OUTPUT FORMAT (print output to the terminal / stdout):

For each test case, output a line containing b and e, representing the amounts of cake Bessie and Elsie respectively will consume if both cows play optimally.

SAMPLE INPUT:

2
4
40 30 20 10
4
10 20 30 40

SAMPLE OUTPUT:

60 40
60 40

For the first test case, under optimal play,

1.Bessie will stack the middle two cakes. The cakes now have sizes [40,50,10].
2.Elsie will eat the leftmost cake. The remaining cakes now have sizes [50,10].
3.Bessie stacks the remaining two cakes.

Bessie will eat 30+20+10=60 cake, while Elsie will eat 40 cake.

The second test case is the reverse of the first, so the answer is the same.

SCORING:

Input 2: All ai  are equal.
Input 3: N≤10
Inputs 4-7: N≤5000
Inputs 8-11: No additional constraints.

Problem credits: Linda Zhao, Agastya Goel, Gavin Ye

扫码领取USACO试题答案+详细解析

咨询一对一备赛规划

USACO竞赛考试网-二维码

2024 年 12 月USACO竞赛金奖组问题三— Job Completion

Bessie the cow has N (1≤N≤2⋅105) jobs for you to potentially complete. The i-th one, if you choose to complete it, must be started at or before time si and takes ti time to complete (0≤si ≤1018,1≤ti ≤1018).

What is the maximum number of jobs you can complete? Time starts at 0
, and once you start a job you must work on it until it is complete, without starting any other jobs in the meantime.

INPUT FORMAT (input arrives from the terminal / stdin):

The first line contains T, the number of independent test cases (1≤T≤10). Each test case is formatted as follows.

The first line contains N.

Each of the next N lines contains two integers si and ti . Row i+1 has the details for the ith job.

It is guaranteed that the sum of N over all test cases does not exceed 3⋅105.

OUTPUT FORMAT (print output to the terminal / stdout):

For each test case, the maximum number of jobs you can complete, on a new line.

SAMPLE INPUT:

3
2
1 4
1 2
2
2 3
1 2
3
1 4
2 3
1 2

SAMPLE OUTPUT:

1
2
2

For the first test case, you can only complete one of the jobs. After completing one job, it will then be time 2 or later, so it is too late to start the other job, which must be started at time 1 or earlier.

For the second test case, you can start the second job at time 0 and finish at time 2, then start the first job at time 2 and finish at time 5.

SCORING:

Inputs 2: Within the same test case, all ti  are equal.
Inputs 3-4: N≤2000, si ,ti ≤2000
Inputs 5-8: N≤2000
Inputs 9-16: No additional constraints.

Problem credits: Benjamin Qi

扫码领取USACO试题答案+详细解析

咨询一对一备赛规划

USACO竞赛考试网-二维码

2024 年 12 月USACO竞赛金奖组问题二— Interstellar Intervals

It's the year 3000 , and Bessie became the first cow in space! During her journey between the stars, she found a number line with N (2≤N≤5⋅105) points, numbered from 1 to N. All points are initially colored white. She can perform the following operation any number of times.

Choose a position i within the number line and a positive integer x. Then, color all the points in the interval [i,i+x−1] red and all points in [i+x , i+2x−1]
blue. All chosen intervals must be disjoint (i.e. no points in [ i, i+2x−1]
can be already colored red or blue). The entire interval must also fall within the number line (i.e. 1≤ii+2x−1≤N).

Farmer John gives Bessie a string s of length N consisting of characters R, B
, and X. The string represents Farmer John's color preferences for each point: si =R means the i'th point must be colored red, si =B means the i'th point must be colored blue, and si =X means there is no constraint on the color for the i'th point.

Help Bessie count the number of distinct ways for the number line to be colored while satisfying Farmer John's preferences. Two colorings are different if there is at least one corresponding point with a different color. Because the answer may be large, output it modulo 109+7.

INPUT FORMAT (input arrives from the terminal / stdin):

The first line contains an integer N.

The following line contains string s.

OUTPUT FORMAT (print output to the terminal / stdout):

Output the number of distinct ways for the number line to be colored while satisfying Farmer John's preferences modulo 109+7.

SAMPLE INPUT:

6
RXXXXB

SAMPLE OUTPUT:

5

Bessie can choose i=1,x=1(i.e. color point 1 red and point 2 blue) and i=3,x=2
(i.e. color points 3,4 red and points 5,6 blue) to produce the coloring RBRRBB.

The other colorings are RRBBRB, RBWWRB, RRRBBB, and RBRBRB.

SAMPLE INPUT:

6
XXRBXX

SAMPLE OUTPUT:

6

The six colorings are WWRBWW, WWRBRB, WRRBBW, RBRBWW, RBRBRB, and RRRBBB.

SAMPLE INPUT:

12

XBXXXXRXRBXX

SAMPLE OUTPUT:

18

SCORING:

Input 4: N≤500
Inputs 5-6: N≤104
Inputs 7-13: All but at most 100 characters in s are X.
Inputs 14-23: No additional constraints

Problem credits: Chongtian Ma, Alex Liang

扫码领取USACO试题答案+详细解析

咨询一对一备赛规划

USACO竞赛考试网-二维码

2024 年 12 月USACO竞赛金奖组问题一—Cowdependence

Farmer John's N (1≤N≤105 ) cows have been arranged into a line. The i
th cow has label ai (1≤ai N). A group of cows can form a friendship group if they all have the same label and each cow is within x cows of all the others in the group, where x is an integer in the range [1,N]. Every cow must be in exactly one friendship group.

For each x from 1 to N , calculate the minimum number of friendship groups that could have formed.

INPUT FORMAT (input arrives from the terminal / stdin):

The first line consists of an integer N.

The next line contains a1...aN , the labels of each cow.

OUTPUT FORMAT (print output to the terminal / stdout):

For each x from 1 to N , output the minimum number of friendship groups for that x on a new line.

SAMPLE INPUT:

9
1 1 1 9 2 1 2 1 1

SAMPLE OUTPUT:

7
5
4
4
4
4
4
3
3

Here are examples of how to assign cows to friendship groups for x=1
and x=2 in a way that minimizes the number of groups. Each letter corresponds to a different group.

SCORING:

Inputs 2-3: N≤5000
Inputs 4-7: ai≤10 for all i
Inputs 8-11: No label appears more than 10 times.
Inputs 12-20: No additional constraints.

Problem credits: Chongtian Ma

扫码领取USACO试题答案+详细解析

咨询一对一备赛规划

USACO竞赛考试网-二维码

2024 年 12 月USACO竞赛白金组问题三—Maximize Minimum Difference

Moo! You are given an integer N (2≤N≤2000). Consider all permutations p=[p0,p1,…,pN−1]of [0,1,2…,N−1]. Let f(p)=|pipi+1|denote the minimum absolute difference between any two consecutive elements of p. and let S denote the set of all p that achieve the maximum possible value of f(p).

You are additionally given K (0≤KN) constraints of the form pi=j (0≤i, j<N). Count the number of permutations in S satisfying all constraints, modulo 109+7.

INPUT FORMAT (input arrives from the terminal / stdin):

The first line contains T (1≤TN≤2⋅104) and N, meaning that you will need to solve T independent test cases, each specified by a different set of constraints.

Each test case starts with K, followed by K lines each containing i and j. It is guaranteed that

The same i does not appear more than once within the same test case.
The same j does not appear more than once within the same test case.

OUTPUT FORMAT (print output to the terminal / stdout):

For each test case, the answer modulo 109+7 on a separate line.

SAMPLE INPUT:

3 4
0
1
1 1
2
0 2
2 3

SAMPLE OUTPUT:

2
0
1

The maximum possible value of f (p) is 2, and S={[2,0,3,1],[1,3,0,2]}.

SAMPLE INPUT:

9 11
2
0 5
6 9
3
0 5
6 9
1 0
4
0 5
6 9
1 0
4 7
5
0 5
6 9
1 0
4 7
2 6
6
0 5
6 9
1 0
4 7
2 6
9 3
7
0 5
6 9
1 0
4 7
2 6
9 3
5 2
8
0 5
6 9
1 0
4 7
2 6
9 3
5 2
7 4
9
0 5
6 9
1 0
4 7
2 6
9 3
5 2
7 4
3 1
10
0 5
6 9
1 0
4 7
2 6
9 3
5 2
7 4
3 1
8 10

SAMPLE OUTPUT:

6
6
1
1
1
1
1
1
1

p=[5,0,6,1,7,2,9,4,10,3,8] should be counted for all test cases.

SAMPLE INPUT:

10 11
0
1
3 8
2
3 8
5 7
3
3 8
5 7
4 2
4
3 8
5 7
4 2
10 6
5
3 8
5 7
4 2
10 6
8 10
6
3 8
5 7
4 2
10 6
8 10
1 9
7
3 8
5 7
4 2
10 6
8 10
1 9
7 5
8
3 8
5 7
4 2
10 6
8 10
1 9
7 5
2 3
9
3 8
5 7
4 2
10 6
8 10
1 9
7 5
2 3
6 0

SAMPLE OUTPUT:

160
20
8
7
2
1
1
1
1
1

p=[4,9,3,8,2,7,0,5,10,1,6]should be counted for all test cases.

SAMPLE INPUT:

5 987
3
654 321
543 210
432 106
2
654 321
543 210
1
654 321
1
0 493
0

SAMPLE OUTPUT:

0
538184948
693625420
932738155
251798971
Make sure to output the answer modulo 109+7.

SCORING:

Input 5: N=15
Input 6: N=2000
Inputs 7-9: For all test cases, the constraint p0=⌊N/2⌋ appears.
Inputs 10-13: For all test cases, there exists some constraint pi =j with j equal to ⌊N/2⌋.
Inputs 14-20: No additional constraints.

Problem credits: Benjamin Qi

扫码领取USACO试题答案+详细解析

咨询一对一备赛规划

USACO竞赛考试网-二维码

2024 年 12 月USACO竞赛白金组问题二—It's Mooin' Time

Bessie has a string of length N(1≤N≤3⋅105) consisting solely of the characters M and O. For each position i of the string, there is a cost ci to change the character at that position to the other character (1≤ci≤108).

Bessie thinks the string will look better if it contains more moos of length L
(1≤L≤min(N,3)). A moo of length L is an M followed by L−1 Os.

For each positive integer k from 1 to ⌊N/L⌋ inclusive, compute the minimum cost to change the string to contain at least k substrings equal to a moo of length L.

INPUT FORMAT (input arrives from the terminal / stdin):

The first line contains L and N.

The next line contains Bessie's length-N string, consisting solely of Ms and Os.

The next line contains space-separated integers c1…cN.

OUTPUT FORMAT (print output to the terminal / stdout):

Output ⌊N/L⌋ lines, the answer for each k in increasing order.

SAMPLE INPUT:

1 4
MOOO
10 20 30 40

SAMPLE OUTPUT:

0
20
50
90

SAMPLE INPUT:

3 4
OOOO
50 40 30 20

SAMPLE OUTPUT:

40

SAMPLE INPUT:

2 20
OOOMOMOOOMOOOMMMOMOO
44743602 39649528 94028117 50811780 97338107 30426846 94909807 22669835 78498782 18004278 16633124 24711234 90542888 88490759 12851185 74589289 54413775 21184626 97688928 10497142

SAMPLE OUTPUT:

0
0
0
0
0
12851185
35521020
60232254
99881782
952304708

SAMPLE INPUT:

3 20
OOOMOMOOOMOOOMMMOMOO
44743602 39649528 94028117 50811780 97338107 30426846 94909807 22669835 78498782 18004278 16633124 24711234 90542888 88490759 12851185 74589289 54413775 21184626 97688928 10497142

SAMPLE OUTPUT:

0
0
0
44743602
119332891
207066974

SCORING:

Input 5: L=3,N≤5000
Input 6: L=1
Inputs 7-10: L=2
Inputs 11-18: L=3

Problem credits: Benjamin Qi

扫码领取USACO试题答案+详细解析

咨询一对一备赛规划

USACO竞赛考试网-二维码

2024 年 12 月USACO竞赛白金组问题一—All Pairs Similarity

Farmer John's N (1≤N≤5⋅105) cows are each assigned a bitstring of length K that is not all zero (1≤K≤20). Different cows may be assigned the same bitstring.

The Jaccard similarity of two bitstrings is defined as the number of set bits in their bitwise intersection divided by the number of set bits in their bitwise union. For example, the Jaccard similarity of the bitstrings 11001 and 11010 would be 2/4.

For each cow, output the sum of her bitstring's Jaccard similarity with each of the N cows' bitstrings including her own, modulo 109+7. Specifically, if the sum is equal to a rational number a/b where a and b are integers sharing no common factors, output the unique integer x in the range [0,109+7) such that bxa is divisible by 109+7.

INPUT FORMAT (input arrives from the terminal / stdin):

The first line contains N and K.

The next N lines each contain an integer i∈(0,2K), representing a cow associated with the length-K binary representation of i.

INPUT FORMAT (input arrives from the terminal / stdin):

Output the sum modulo 109+7 for each cow on a separate line.

SAMPLE INPUT:

4 2
1
1
2
3

SAMPLE OUTPUT:

500000006
500000006
500000005
500000006

The cows are associated with the following bitstrings: [01,01,10,11].

For the first cow, the sum is  sim(1,1)+sim(1,1)+sim(1,2)+sim(1,3)=1+1+0+1/2≡500000006(mod 109+7).

The second cow's bitstring is the same as the first cow's, so her sum is the same as above.

For the third cow, the sum is

sim(2,1)+sim(2,1)+sim(2,2)+sim(2,3)=0+0+1+1/2≡500000005(mod 109+7).

SCORING:

Inputs 2-15: There will be two test cases for each of K∈{10,15,16,17,18,19,20}.

Problem credits: Benjamin Qi

扫码领取USACO试题答案+详细解析

咨询一对一备赛规划

USACO竞赛考试网-二维码

USACO竞赛如何判分?晋级要求是?成绩可以保留多久?

对于希望申请藤校、牛津、剑桥等世界顶尖高等学府的学生来说,USACO的成绩不仅是学术能力的证明,更是个性化申请材料中的亮点。很多院校在招生时非常重视申请者的参与经历与竞赛成绩,USACO的金奖和白金奖更是被视为优秀候选人的重要指标。

考试内容

编程语言支持

USACO目前支持多种编程语言,包括但不限于C、C++、Java、Python。虽然官方曾支持Pascal,但近年来较少使用。C++因为其执行效率高且与NOIP兼容性好,成为大多数参赛者的首选。

考试难度 USACO竞赛各等级难度依次递增。难度相当于NOIP普及组-、NOIP提高组-、NOIP提高组+、NOI-。月赛的题目与IOI试题类型大致相同,绝大多数为传统试题,采用IOI赛制。

评分规则

2025年USACO竞赛四个级别比赛都是3道题,总分1000分。每道题333.3分。每道题有10个测试点,通过一个可得33.33分。

判分方式

2025年USACO竞赛和NOI系列赛事相同,即依据程序所能正确求解的测试点数量按比例计分。

对于各个测试点,一般题目会标注相应的时限要求和内存要求(如未具体标注,则C/C++/Pascal默认时限2秒,Java/Python默认时限4秒,内存均默认256MB)。

下面是不同级别的晋级分数要求:

铜升银:700-800分

银升金:650-750分

金升铂金:750分+

每年USACO的三场月赛+一场公开赛为一个赛季,每年的赛季成绩不会保留到次年,也就是说如果你24-25赛季拿到了金级,这个成绩不能保留到明年,如果你想在25-26赛季中进阶到铂金级,还是需要从“铜”开始

USACO竞赛培训

USACO(美国计算机奥林匹克)竞赛是一项旨在提升学生编程能力和算法思维的重要赛事。为了帮助学生更好地备战USACO,特设立了专门的USACO培训课程。这些课程是根据USACO指南网站上的考点需求,由经验丰富的专业教师设计并开发的。

哥大和清华学姐带队!为参赛者提供专业的指导和实战经验分享

课程亮点

系统性学习竞赛知识点,为冲刺奖项做准备;

课程内容更加紧凑,更加注重核心知识点的讲解,学习强度比较大;

提前学习IB/AP/AL计算机之外的知识点,提高计算机校内成绩。

课程大纲

USACO铜级

USACO银级

扫码抢先报名课程,名额有限,先到先得!

USACO竞赛考试网-二维码

思维导图

USACO 2024-2025赛季已经开赛!准备USACO的最佳方法了解一下!

USACO作为全球最具知名度的中学生编程竞赛之一,已经成为通往国际计算机科学奥林匹克竞赛(IOI)的重要途径。2024年USACO首场考试刚刚结束,2024USACO考试时间有三场,现在才刚刚考完第一场!

准备USACO的最佳方法

USACO是一项高水平的计算机编程竞赛,旨在培养学生的算法设计、编程能力和问题解决能力。为了帮助你在USACO竞赛中取得优异成绩,以下是一个详细的备赛指南,涵盖从基础知识到实战演练的各个方面。

1.打好基础

选择编程语言:

选择一种你感兴趣的编程语言: C++、Python和Java是USACO中最常用的编程语言。

  - C++:性能高,标准模板库(STL)丰富,适合对性能要求较高的题目。

  - Python:语法简洁,适合快速开发和调试,但执行速度较慢。

  - Java:性能介于C++和Python之间,拥有丰富的类库。

调整编程习惯:

  - 类名和源文件名一致:确保类名和源文件名一致,避免编译错误。

  - 代码规范:保持良好的代码规范,例如变量命名、缩进、注释等,提高代码可读性。

基础实践:

算法理解:深入理解常见算法,例如排序、搜索、动态规划、贪心算法等。

问题解决策略:学习如何将问题分解为更小的子问题,并设计相应的算法解决。

基础练习:

- 保持练习:每天进行基础练习,巩固编程语言和算法知识。

- 代码实现:尝试手动实现常见算法,例如快速排序、二分查找等。

2.了解数据结构的应用

数据结构的动态性:

- 理解数据结构:数据结构是动态的实体,例如数组、链表、栈、队列、树、图、哈希表等。

- 应用场景:了解每种数据结构的应用场景,例如链表在动态内存分配中的应用,树在层次结构中的应用。

时间复杂度:

- 分析时间复杂度:了解不同数据结构在不同操作上的时间复杂度,例如数组的随机访问时间复杂度为O(1),链表的插入和删除时间复杂度为O(n)。

结合算法:

- 选择合适的数据结构:根据问题的需求选择合适的数据结构,并将其与正确的算法结合进行编码。

3.熟练编程语言

复习与学习:

- 熟练掌握者:如果你已经熟练掌握C++、Python或Java,可以快速复习语法和常用库。

- 初学者:如果你对这些编程语言了解较少,需要系统学习语法、常用库和编程技巧。

实践练习:

- 编写代码:每天编写代码,解决实际问题,巩固编程语言知识。

- 调试技巧:学习调试技巧,例如使用调试器、打印调试信息等,提高调试效率。

4.多练习

随机问题和测试案例:

- 练习随机问题:在USACO官网和其他在线平台上练习随机问题,熟悉不同类型的题目。

- 测试案例:编写测试案例,验证代码的正确性。

计时练习:

- 设定计时器:设定计时器,模拟竞赛环境,在规定时间内解决问题。

- 时间管理:练习时间管理,确保能够在4小时内解决三个问题。

持续练习:

- 每日练习:每天坚持练习,保持良好的竞技状态。

- 总结经验:每次练习后总结经验教训,找出不足之处并加以改进。

5.寻找最佳答案

多解法思考:

- 多种解法:大多数问题都有一个或多个解决方案,尝试寻找多种解法。

- 比较优劣:比较不同解法的优劣,选择最优解法。

算法空间理解:

- 算法优化:通过对算法空间的理解,优化算法,提高代码效率。

- 时间与空间平衡:在时间复杂度和空间复杂度之间找到平衡,选择最优的解决方案。

6.参加USACO竞赛

实战演练:

参加竞赛:尽可能多地参加USACO竞赛,积累实战经验。

模拟考试:进行全真模拟考试,严格按照竞赛时间和规则进行训练。

自我评估:

- 犯错误:犯错误是另一种练习方式,通过错误学习经验。

- 自我批评:自我评估是最好的批评,分析错误原因,总结经验教训。

参考学习资源:

- 学习资源:参考USACO官网和其他学习资源,学习优秀代码和解决方案。

- 持续改进:根据学习资源提供的建议,不断改进自己的代码和算法。

【扫码免费领取】USACO真题+备赛书单+一对一备考规划!

预约最新真题讲座、课程详情可扫码咨询⇓

思维导图