USACO 2月 2021-2022 February Contest Silver银组 题解

本文精选三道USACO题目进行解析,涵盖算法优化、组合计数与模拟操作等核心内容,帮助参赛者理解题意并提供高效解题思路。

要准备usaco的铁铁们可以参考这个文章哦!

想刷好USACO——看这篇文章就够了_GeekAlice的博客-优快云博客usaco 必刷网站https://blog.youkuaiyun.com/GeekAlice/article/details/122291933

Problem 1. Redistributing Gifts

Farmer John has N gifts labeled 1…N for his N cows, also labeled 1…N(1≤N≤500). Each cow has a wishlist, which is a permutation of all N gifts such that the cow prefers gifts that appear earlier in the list over gifts that appear later in the list.

FJ was lazy and just assigned gift i to cow i for all i. Now, the cows have gathered amongst themselves and decided to reassign the gifts such that after reassignment, every cow ends up with the same gift as she did originally, or a gift that she prefers over the one she was originally assigned.

For each i from 1 to N, compute the most preferred gift cow i could hope to receive after reassignment.

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

The first line contains N. The next N lines each contain the preference list of a cow. It is guaranteed that each line forms a permutation of 1…N.

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

Please output NN lines, the ii-th of which contains the most preferred gift cow ii could hope to receive after reassignment.

SAMPLE INPUT:

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

SAMPLE OUTPUT:

1
3
2
4

In this example, there are two possible reassignments:

  • The original assignment: cow 1 receives gift 11, cow 22 receives gift 22, cow 33 receives gift 33, and cow 44 receives gift 44.
  • Cow 11 receives gift 11, cow 22 receives gift 33, cow 33 receives gift 22, and cow 44 receives gift 44.

Observe that both cows 11 and 44 cannot hope to receive better gifts than they were originally assigned. However, both cows 22 and 33 can.

SCORING:

  • Test cases 2-3 satisfy N≤8N≤8.
  • Test cases 4-11 satisfy no additional constraints.

        只有当奶牛 i 接收奶牛 j 的分布对应于将 G 的顶点划分为一些包含边 i→j 的简单循环。由此可见,其中一个简单循环包含边 i→j。如果存在一个包含i→j的简单圈C。然后我们可以将 C 上的每头奶牛分配给循环中下一头奶牛的礼物,C 上的每头奶牛最终都会过得更好。让所有不在 C 沿线的奶牛都收到它们原来的礼物。这对应于有效分布。

#incl
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值