USACO 2022 February Contest, Bronze

 Problem 1. Sleeping in Class

Bessie the cow was excited to recently return to in-person learning! Unfortunately, her instructor, Farmer John, is a very boring lecturer, and so she ends up falling asleep in class often.

Farmer John has noticed that Bessie has not been paying attention in class. He has asked another student in class, Elsie, to keep track of the number of times Bessie falls asleep in a given class. There are NN class periods (1≤N≤1051≤N≤105), and Elsie logs that Bessie fell asleep aiai times (0≤ai≤1060≤ai≤106) in the ii-th class period. The total number of times Bessie fell asleep across all class periods is at most 106106.

Elsie, feeling very competitive with Bessie, wants to make Farmer John feel like Bessie is consistently falling asleep the same number of times in every class -- making it appear that the issue is entirely Bessie's fault, with no dependence on Farmer John's sometimes-boring lectures. The only way Elsie may modify the log is by combining two adjacent class periods. For example, if a=[1,2,3,4,5],a=[1,2,3,4,5], then if Elsie combines the second and third class periods the log will become [1,5,4,5][1,5,4,5].

Help Elsie compute the minimum number of modifications to the log that she needs to make so that she can make all the numbers in the log equal.

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

Each input will contain TT (1≤T≤101≤T≤10) test cases that should be solved independently.

The first line contains TT, the number of test cases to be solved. The TT test cases follow, each described by a pair of lines. The first line of each pair contains NN, and the second contains a1,a2,…,aNa1,a2,…,aN.

It is guaranteed that within each test case, the sum of all values in aa is at most 106106. It is also guaranteed that the sum of NN over all test cases is at most 10^5.

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

Please write TT lines of output, giving the minimum number of modifications Elsie could perform to make all the log entries equal for each case.

SAMPLE INPUT:

3
6
1 2 3 1 1 1
3
2 2 3
5
0 0 0 0 0

SAMPLE OUTPUT:

3
2
0

For the first test case in this example, Elsie can change her log to consist solely of 3s with 3 modifications.

   1 2 3 1 1 1
-> 3 3 1 1 1
-> 3 3 2 1
-> 3 3 3

For the second test case, Elsie can change her log to 7 with 2 modifications.

   2 2 3
-> 2 5
-> 7

For the last test case, Elsie doesn’t need to perform any operations; the log already consists of equal entries.

Problem credits: Jesse Choe


 Problem 2. Photoshoot 2

In what seems to be a familiar occurrence, Farmer John is lining up his NN cows (1≤N≤1051≤N≤105), conveniently numbered 1…N1…N, for a photograph.

Initially, the cows are lined up in the order a1,a2,…,aNa1,a2,…,aN from left to right. Farmer John's goal is to line up the cows in the order b1,…,bNb1,…,bN from left to right. To accomplish this, he may perform a series of modifications to the ordering. Each modification consists of choosing a single cow and moving it some number of positions to the left.

Please count the minimum number of modifications required in order for Farmer John to line up his cows in the desired order.

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

The first line of input contains NN. The second line contains a1,a2,…,aNa1,a2,…,aN. The third line contains b1,b2,…,bNb1,b2,…,bN.

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

Print the minimum number of modifications required to produce Farmer John's desired ordering.

SAMPLE INPUT:

5
1 2 3 4 5
1 2 3 4 5

SAMPLE OUTPUT:

0

In this example, the cows are already in the desired order, so no modifications are required.

SAMPLE INPUT:

5
5 1 3 2 4
4 5 2 1 3

SAMPLE OUTPUT:

2

In this example, two modifications suffice. Here is one way Farmer John can rearrange his cows:

  1. Choose cow 44 and move it four positions to the left.
  2. Choose cow 22 and move it two positions to the left.

   5 1 3 2 4
-> 4 5 1 3 2
-> 4 5 2 1 3

SCORING:

  • Test cases 3-6 satisfy N≤100N≤100.
  • Test cases 7-10 satisfy N≤5000N≤5000.
  • Test cases 11-14 satisfy no additional constraints.

Problem credits: Benjamin Qi


Problem 3. Blocks

In an effort to improve her vocabulary, Bessie the cow has obtained a set of four wooden blocks, each one a cube with a letter of the alphabet written on each of its six sides. She is learning how to spell by arranging the blocks in a row so the letters on top of the blocks spell words.

Given the letters on each of Bessie's four blocks, and a list of words she would like to spell, please determine which of words on her list she will be able to spell successfully using the blocks.

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

The first line of input contains NN (1≤N≤101≤N≤10), the number of words that Bessie would like to spell. The next four lines each contain a string with six uppercase letters, representing the letters on the six sides of one of Bessie's blocks. The next NN lines contain the NN words Bessie would like to spell. Each of these is between 1 and 4 uppercase letters long.

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

For each word on Bessie's list, output YES if she is able to spell it using the blocks and NO otherwise.

SAMPLE INPUT:

6
MOOOOO
OOOOOO
ABCDEF
UVWXYZ
COW
MOO
ZOO
MOVE
CODE
FARM

SAMPLE OUTPUT:

YES
NO
YES
YES
NO
NO

In this example, Bessie can spell COW, ZOO, and MOVE. Sadly, she cannot spell MOO, since the only block with an M cannot also be used for an O. She cannot spell FARM since there is no block with a letter R. She cannot spell CODE since the C, D, and E all belong to the same block.

Problem credits: Brian Dean

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值