要准备usaco的铁铁们可以参考这个文章哦!
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

本文精选三道USACO题目进行解析,涵盖算法优化、组合计数与模拟操作等核心内容,帮助参赛者理解题意并提供高效解题思路。
https://blog.youkuaiyun.com/GeekAlice/article/details/122291933
最低0.47元/天 解锁文章
1222

被折叠的 条评论
为什么被折叠?



