Download as pdf or txt
Download as pdf or txt
You are on page 1of 41

Usaco 总结  lzoi leokan  http://hi.baidu.

com/leokan/ 

我的 usaco  总结 
 
Personalized Curriculum for Leo Kan; Last visit: 12 hours ago   
Congratulations! You have finished all available material. 
 
Chapter 1 DONE 2008.03.16 Getting started   
Chapter 2 DONE 2008.01.30 Bigger Challenges   
Chapter 3 DONE 2008.02.15 Techniques more subtle   
Chapter 4 DONE 2008.03.09 Advanced algorithms and difficult drills   
Chapter 5 DONE 2008.04.04 Serious challenges   
Chapter 6 DONE 2008.04.03 Contest Practice   
 
花了几个月时间,做完了 USACO,感觉收获很大.做 USACO 之前和做 USACO 之
后我感觉我的能力有很大的提升. 
 
USACO 这个题库是一个完全适合信息学竞赛初学者的题库,它里面的内容由
浅至难,很"经典"的一题 Your Ride Is Here 是只要会编程就能做的题目.接下来的内
容可以使你掌握信息学竞赛中一些基本的也是很必要的算法和数据结构.如果只
是想参加 noip 的话做完 4 甚至还不用就有拿奖的水平了(noip 甚至连网络流,几何
都不考) 
 

Chapter 1, 
 
正如它的标题所言 Getting started,如果你只会编程而想踏入竞赛的门槛的话,
做完 Getting  started,你就能对什么是竞赛有一点认识了.涉及基础的贪心,动态规
划,搜索,模拟.特别需要提一下的我觉得是 Checker  Challenge  如果不用位运算那
么它的剪枝有很大的技巧,很有启发性.另外 Packing Rectangles 是一道极度繁琐的
题目,不考什么技巧,就考是否细心,如果是初学者很有必要练习一下,不是的话可
以直接 pass. 
 
DONE 2007.10.25 TEXT Introduction   
Section 1.1 DONE 2008.03.16 TEXT Submitting Solutions   
DONE 2007.10.26 PROB Your Ride Is Here [ANALYSIS]  无聊题 
DONE 2007.10.26 TEXT Contest Problem Types   
DONE 2007.10.26 TEXT Ad Hoc Problems   
DONE 2007.10.26 PROB Greedy Gift Givers [ANALYSIS]  模拟 
DONE 2007.10.27 PROB Friday the Thirteenth [ANALYSIS]  模拟 
DONE 2007.10.27 PROB Broken Necklace [ANALYSIS]  枚举 or 动态规划 
Section 1.2 DONE 2007.10.27 TEXT Complete Search   
DONE 2007.12.30 PROB Milking Cows [ANALYSIS]  贪心 
DONE 2007.12.30 PROB Transformations [ANALYSIS]  模拟 
Usaco 总结  lzoi leokan  http://hi.baidu.com/leokan/ 

DONE 2007.12.31 PROB Name That Number [ANALYSIS]  模拟 
DONE 2007.12.31 PROB Palindromic Squares [ANALYSIS]  模拟 
DONE 2007.12.31 PROB Dual Palindromes [ANALYSIS]  模拟 
Section 1.3 DONE 2007.12.31 TEXT Greedy Algorithm   
DONE  2007.12.31  PROB  Mixing  Milk  [ANALYSIS]  标准解法该是线段覆盖或线段树
吧,但是作为 chapter1  的题可以试试模拟 
DONE 2007.12.31 PROB Barn Repair [ANALYSIS]  贪心 
DONE 2007.12.31 TEXT Winning Solutions   
DONE 2008.01.01 PROB Calf Flac [ANALYSIS]  枚举 
DONE 2008.01.01 PROB Prime Cryptarithm [ANALYSIS]  枚举 
Section 1.4 DONE 2008.01.01 TEXT More Search Techniques   
DONE 2008.01.25 PROB Packing Rectangles [ANALYSIS]  模拟 
DONE 2008.01.14 PROB The Clocks [ANALYSIS]  搜索 or 枚举还有一种数学方法的 
DONE 2008.01.25 PROB Arithmetic Progressions [ANALYSIS]  枚举 
DONE 2008.01.04 PROB Mother's Milk [ANALYSIS]  搜索 
Section 1.5 DONE 2008.01.25 TEXT Introduction to Binary Numbers   
DONE 2008.01.25 PROB Number Triangles [ANALYSIS]  动态规划 
DONE 2008.01.26 PROB Prime Palindromes [ANALYSIS]  枚举 
DONE 2008.01.26 PROB SuperPrime Rib [ANALYSIS]  枚举 
DONE 2008.01.26 PROB Checker Challenge [ANALYSIS]  搜索 
 

Chapter 2, 
  它涉及一些算法了,比较基础的就是最短路径的 Bessie  Come  Home,还有很大
一部分是练习编程技巧的,其中一个比较实用的—位运算. 
 
Section 2.1 DONE 2008.01.26 TEXT Graph Theory   
DONE 2008.01.26 TEXT Flood Fill Algorithms   
DONE 2008.01.27 PROB The Castle [ANALYSIS] Flood Fill 
DONE 2008.01.27 PROB Ordered Fractions [ANALYSIS]  枚举 or 递归 
DONE 2008.01.27 PROB Sorting A Three‐Valued Sequence [ANALYSIS]  贪心 
DONE 2008.01.27 PROB Healthy Holsteins [ANALYSIS]  搜索 
DONE 2008.01.27 PROB Hamming Codes [ANALYSIS]  枚举(位运算) 
Section 2.2 DONE 2008.01.27 TEXT Data Structures   
DONE 2008.01.27 TEXT Dynamic Programming   
DONE 2008.01.28 PROB Preface Numbering [ANALYSIS]  模拟 
DONE 2008.01.28 PROB Subset Sums [ANALYSIS]  动态规划 
DONE 2008.01.28 PROB Runaround Numbers [ANALYSIS]  模拟 
DONE 2008.01.28 PROB Party Lamps [ANALYSIS]  枚举(位运算) 
Section 2.3 DONE 2008.01.28 PROB The Longest Prefix [ANALYSIS]  动态规划 
DONE 2008.01.29 PROB Cow Pedigrees [ANALYSIS]  动态规划 
DONE 2008.01.29 PROB Zero Sum [ANALYSIS]  搜索 
DONE 2008.01.29 PROB Money Systems [ANALYSIS]  动态规划(背包模型) 
DONE 2008.01.29 PROB Controlling Companies [ANALYSIS]  搜索 
Usaco 总结  lzoi leokan  http://hi.baidu.com/leokan/ 

Section 2.4 DONE 2008.01.29 TEXT Shortest Paths   
DONE 2008.01.30 PROB The Tamworth Two [ANALYSIS]  搜索 
DONE 2008.01.30 PROB Overfencing [ANALYSIS]  搜索 
DONE 2007.11.25 PROB Cow Tours [ANALYSIS]  最短路 
DONE 2007.11.03 PROB Bessie Come Home [ANALYSIS]  最短路 
DONE 2008.01.30 PROB Fractions to Decimals [ANALYSIS]  模拟 
 

Chapter 3, 
  更多的算法,最小生成树的 Agri‐Net,欧拉回路的 Riding  The  Fences,  Sweet 
Butter 这一题是最短路径,不过这题完全可以作为从初级图论题到中级图论题的
一个过渡,需要用到 bellman‐ford 或 SPFA,当然 heap  dijkstra 也可以,再高级的
Chapter 3 的程度还未到,可以先不学. 
Home on the Range 这题的动态规划是 USACO  从 Chapter1  开始以来新的一种动
态规划方式,是在一个矩阵中判断一个位置和附近位置关系得到的状态转移方程. 
Feed  Ratios 这题可以枚举,但是有更好的方法(高斯消元,克莱姆法则…关于克莱姆
法则请参见附录).closed fences 是 USACO 的第一道几何题,详细题解看附录. 
 
Section 3.1 DONE 2008.01.30 TEXT Minimal Spanning Trees   
DONE 2007.11.03 PROB Agri‐Net [ANALYSIS] MST 
DONE 2008.01.31 PROB Score Inflation [ANALYSIS]  动态规划 
DONE 2008.01.31 PROB Humble Numbers [ANALYSIS]  枚举 
DONE 2008.01.31 PROB Shaping Regions [ANALYSIS]  线段树 or 矩形覆盖 
DONE 2008.02.01 PROB Contact [ANALYSIS]  模拟 
DONE 2008.02.01 PROB Stamps [ANALYSIS]  动态规划(背包模型) 
Section 3.2 DONE 2008.02.01 TEXT Knapsack Problems   
DONE 2007.12.02 PROB Factorials [ANALYSIS]  可以用错误方法(保留部分位)过这题,
但是这样做是错误的,仅仅对于小数据有效,正确方法是统计 2 和 5  的个数然后计
算 
DONE 2008.02.01 PROB Stringsobits [ANALYSIS]  康托展开 
DONE 2008.02.02 PROB Spinning Wheels [ANALYSIS]  模拟 
DONE 2007.11.19 PROB Feed Ratios [ANALYSIS]  枚举 or 高斯消元 or 克莱姆法则 
DONE 2008.02.02 PROB Magic Squares [ANALYSIS]  搜索 
DONE 2008.02.05 PROB Sweet Butter [ANALYSIS]  最短路 
Section 3.3 DONE 2008.02.05 TEXT Eulerian Tours   
DONE 2008.02.05 PROB Riding The Fences [ANALYSIS]  欧拉路 
DONE 2008.02.08 PROB Shopping Offers [ANALYSIS]  动态规划(背包模型) 
DONE 2008.02.09 PROB Camelot [ANALYSIS]  搜索+贪心 
DONE 2008.02.09 PROB Home on the Range [ANALYSIS]  动态规划 
DONE 2008.02.09 PROB A Game [ANALYSIS]  动态规划 
Section 3.4 DONE 2008.02.12 TEXT Computational Geometry   
DONE 2008.02.12 PROB Closed Fences [ANALYSIS]  几何 
DONE 2007.11.22 PROB American Heritage [ANALYSIS]  递归,经典,入门必做 
DONE 2008.02.15 PROB Electric Fence [ANALYSIS] pick 公式(其实直接枚举效率更高
Usaco 总结  lzoi leokan  http://hi.baidu.com/leokan/ 

且简单) 
DONE 2008.02.15 PROB Raucous Rockers [ANALYSIS]  动态规划(背包模型) 
 

Chapter 4, 
  可以找到一点点竞赛感觉了…算法方面有网络流 Drainage  Ditches,二分图最
大匹配 The  Perfect  Stall,很多经典问题,例如 Pollutant  Control 的求最小割集. 
Chapter 4 的每一题都很有价值,对于初学者能长很多经验的比如 dfsid 这种搜索技
巧. 
 
Section 4.1 DONE 2008.02.18 TEXT Optimization Techniques   
DONE 2008.02.19 PROB Beef McNuggets [ANALYSIS]  动态规划+枚举 
DONE 2008.03.01 PROB Fence Rails [ANALYSIS]  搜索(dfsid) 
DONE 2008.02.20 PROB Fence Loops [ANALYSIS]  最小环(它给出的是边的联通关系
而不是点的联通关系)对于这种需要自己构图的题目可以用搜索. 
DONE 2008.02.22 PROB Cryptcowgraphy [ANALYSIS]  搜索+elfhash 
Section 4.2 DONE 2008.03.01 TEXT "Network Flow" Algorithms   
DONE 2008.02.22 PROB Drainage Ditches [ANALYSIS]  网络流 
DONE 2007.12.11 PROB The Perfect Stall [ANALYSIS]  二分图匹配 
DONE 2008.03.02 PROB Job Processing [ANALYSIS]  动态规划+贪心 
DONE 2008.03.02 PROB Cowcycles [ANALYSIS]  搜索 
Section 4.3 DONE 2008.03.03 TEXT Big Numbers   
DONE 2007.12.02 PROB Buy Low, Buy Lower [ANALYSIS]  动态规划(最长不下降子序
列) 
DONE 2008.03.05 PROB The Primes [ANALYSIS]  搜索,优化可以很多的,很有趣味性 
DONE 2008.03.07 PROB Street Race [ANALYSIS]  求割点,搜索 
DONE 2008.03.07 PROB Letter Game [ANALYSIS]  枚举,我觉得它主要考预处理,预处
理后其实只需枚举几十个 
Section 4.4 DONE 2008.03.07 PROB Shuttle Puzzle [ANALYSIS]   
DONE 2008.03.08 PROB Pollutant Control [ANALYSIS]  最小割 
DONE 2008.03.09 PROB Frame Up [ANALYSIS]  拓扑排序 
 

Chapter 5, 
很耐人寻味的一个章节,全是好题 
 
Section 5.1 DONE 2008.03.14 TEXT Convex Hulls   
DONE 2008.03.11 PROB Fencing the Cows [ANALYSIS]  凸包 
DONE 2008.03.14 PROB Starry Night [ANALYSIS] flood fill 
DONE 2008.03.15 PROB Musical Themes [ANALYSIS]  动态规划 or 枚举 
Section 5.2 DONE 2008.03.16 PROB Snail Trail [ANALYSIS]  搜索 
DONE 2008.03.16 PROB Electric Fences [ANALYSIS]  几何 
DONE  2008.03.17  PROB  Wisconsin  Squares  [ANALYSIS]  搜索,数据结构上如果用表
能有很好的效果 
Usaco 总结  lzoi leokan  http://hi.baidu.com/leokan/ 

Section 5.3 DONE 2008.03.19 TEXT Heuristics & Approximate Searches   
DONE  2008.03.20  PROB  Milk  Measuring  [ANALYSIS]  动态规划 or  dfsid+动态规划
/dfs(用 dfs 对于这题数据能有很好的效果 0s 出解) 
DONE 2008.03.21 PROB Window Area [ANALYSIS]  模拟+矩形覆盖 
DONE 2008.03.22 PROB Network of Schools [ANALYSIS]  图的连通性 
DONE 2008.03.22 PROB Big Barn [ANALYSIS]  动态规划 
Section 5.4 DONE 2008.03.23 PROB All Latin Squares [ANALYSIS]  搜索 or 错排(数学
性很强,推广很难) 
DONE 2008.03.25 PROB Canada Tour [ANALYSIS]  网络流 or 动态规划 
DONE 2008.04.04 PROB Character Recognition [ANALYSIS]  统计+动态规划 
DONE 2008.03.28 PROB Betsy's Tour [ANALYSIS]  搜索 
DONE 2008.03.29 PROB TeleCowmunication [ANALYSIS]  最小割 
Section 5.5 DONE 2008.03.30 PROB Picture [ANALYSIS]  线段树 
DONE 2008.03.30 PROB Hidden Passwords [ANALYSIS]  枚举+KMP 思想优化 
DONE 2008.04.04 PROB Two Five [ANALYSIS]  搜索+康托展开 

Chapter 6, 
只有几题 
 
Section 6.1 DONE 2008.04.01 PROB Postal Vans [ANALYSIS]  动态规划 
DONE 2008.04.02 PROB A Rectangular Barn [ANALYSIS]  动态规划 
DONE 2008.04.03 PROB Cow XOR [ANALYSIS]  枚举+优化 
Usaco 总结  lzoi leokan  http://hi.baidu.com/leokan 

附录一:题解索引 
Section 1.0 DONE 2007.10.25 (1.1 的题目程序丢了,不必看 1.1 的题解)
DONE 2008.03.16 TEXT Submitting Solutions
DONE 2007.10.26 PROB Your Ride Is Here [ANALYSIS]
DONE 2007.10.26 TEXT Contest Problem Types
Section 1.1 DONE 2007.10.26 TEXT Ad Hoc Problems
DONE 2007.10.26 PROB Greedy Gift Givers [ANALYSIS]
DONE 2007.10.27 PROB Friday the Thirteenth [ANALYSIS]
DONE 2007.10.27 PROB Broken Necklace [ANALYSIS]
DONE 2007.10.27 TEXT Complete Search
DONE 2007.12.30 PROB Milking Cows [ANALYSIS]
DONE 2007.12.30 PROB Transformations [ANALYSIS]
Section 1.2
DONE 2007.12.31 PROB Name That Number [ANALYSIS]
DONE 2007.12.31 PROB Palindromic Squares [ANALYSIS]
DONE 2007.12.31 PROB Dual Palindromes [ANALYSIS]
DONE 2007.12.31 TEXT Greedy Algorithm
DONE 2007.12.31 PROB Mixing Milk [ANALYSIS]
DONE 2007.12.31 PROB Barn Repair [ANALYSIS]
Section 1.3
DONE 2007.12.31 TEXT Winning Solutions
DONE 2008.01.01 PROB Calf Flac [ANALYSIS]
DONE 2008.01.01 PROB Prime Cryptarithm [ANALYSIS]
DONE 2008.01.01 TEXT More Search Techniques
DONE 2008.01.25 PROB Packing Rectangles [ANALYSIS]
Section 1.4 DONE 2008.01.14 PROB The Clocks [ANALYSIS]
DONE 2008.01.25 PROB Arithmetic Progressions [ANALYSIS]
DONE 2008.01.04 PROB Mother's Milk [ANALYSIS]
DONE 2008.01.25 TEXT Introduction to Binary Numbers
DONE 2008.01.25 PROB Number Triangles [ANALYSIS]
Section 1.5 DONE 2008.01.26 PROB Prime Palindromes [ANALYSIS]
DONE 2008.01.26 PROB SuperPrime Rib [ANALYSIS]
DONE 2008.01.26 PROB Checker Challenge [ANALYSIS]
DONE 2008.01.26 TEXT Graph Theory
Section
DONE 2008.01.26 TEXT Flood Fill Algorithms
2.1
DONE 2008.01.27 PROB The Castle [ANALYSIS]
Usaco 总结  lzoi leokan  http://hi.baidu.com/leokan 

DONE 2008.01.27 PROB Ordered Fractions [ANALYSIS]


PROB Sorting A Three-Valued
DONE 2008.01.27
Sequence [ANALYSIS]
DONE 2008.01.27 PROB Healthy Holsteins [ANALYSIS]
DONE 2008.01.27 PROB Hamming Codes [ANALYSIS]
DONE 2008.01.27 TEXT Data Structures
DONE 2008.01.27 TEXT Dynamic Programming
Section DONE 2008.01.28 PROB Preface Numbering [ANALYSIS]
2.2 DONE 2008.01.28 PROB Subset Sums [ANALYSIS]
DONE 2008.01.28 PROB Runaround Numbers [ANALYSIS]
DONE 2008.01.28 PROB Party Lamps [ANALYSIS]
DONE 2008.01.28 PROB The Longest Prefix [ANALYSIS]
DONE 2008.01.29 PROB Cow Pedigrees [ANALYSIS]
Section
DONE 2008.01.29 PROB Zero Sum [ANALYSIS]
2.3
DONE 2008.01.29 PROB Money Systems [ANALYSIS]
DONE 2008.01.29 PROB Controlling Companies [ANALYSIS]
DONE 2008.01.29 TEXT Shortest Paths
DONE 2008.01.30 PROB The Tamworth Two [ANALYSIS]
Section DONE 2008.01.30 PROB Overfencing [ANALYSIS]
2.4 DONE 2007.11.25 PROB Cow Tours [ANALYSIS]
DONE 2007.11.03 PROB Bessie Come Home [ANALYSIS]
DONE 2008.01.30 PROB Fractions to Decimals [ANALYSIS]
 
DONE 2008.01.30 TEXT Minimal Spanning Trees
DONE 2007.11.03 PROB Agri-Net [ANALYSIS]
DONE 2008.01.31 PROB Score Inflation [ANALYSIS]
Section 3.1 DONE 2008.01.31 PROB Humble Numbers [ANALYSIS]
DONE 2008.01.31 PROB Shaping Regions [ANALYSIS]
DONE 2008.02.01 PROB Contact [ANALYSIS]
DONE 2008.02.01 PROB Stamps [ANALYSIS]
DONE 2008.02.01 TEXT Knapsack Problems
DONE 2007.12.02 PROB Factorials [ANALYSIS]
Section 3.2 DONE 2008.02.01 PROB Stringsobits [ANALYSIS]
DONE 2008.02.02 PROB Spinning Wheels [ANALYSIS]
DONE 2007.11.19 PROB Feed Ratios [ANALYSIS]
Usaco 总结  lzoi leokan  http://hi.baidu.com/leokan 

DONE 2008.02.02 PROB Magic Squares [ANALYSIS](程序丢了)


DONE 2008.02.05 PROB Sweet Butter [ANALYSIS]
DONE 2008.02.05 TEXT Eulerian Tours
DONE 2008.02.05 PROB Riding The Fences [ANALYSIS]
DONE 2008.02.08 PROB Shopping Offers [ANALYSIS]
Section 3.3
DONE 2008.02.09 PROB Camelot [ANALYSIS]
DONE 2008.02.09 PROB Home on the Range [ANALYSIS]
DONE 2008.02.09 PROB A Game [ANALYSIS]
DONE 2008.02.12 TEXT Computational Geometry
DONE 2008.02.12 PROB Closed Fences [ANALYSIS]
Section 3.4 DONE 2007.11.22 PROB American Heritage [ANALYSIS]
DONE 2008.02.15 PROB Electric Fence [ANALYSIS]
DONE 2008.02.15 PROB Raucous Rockers [ANALYSIS]
 
DONE 2008.02.18 TEXT Optimization Techniques
DONE 2008.02.19 PROB Beef McNuggets [ANALYSIS]
Section 4.1 DONE 2008.03.01 PROB Fence Rails [ANALYSIS]
DONE 2008.02.20 PROB Fence Loops [ANALYSIS]
DONE 2008.02.22 PROB Cryptcowgraphy [ANALYSIS]
DONE 2008.03.01 TEXT "Network Flow" Algorithms
DONE 2008.02.22 PROB Drainage Ditches [ANALYSIS]
Section 4.2 DONE 2007.12.11 PROB The Perfect Stall [ANALYSIS]
DONE 2008.03.02 PROB Job Processing [ANALYSIS]
DONE 2008.03.02 PROB Cowcycles [ANALYSIS]
DONE 2008.03.03 TEXT Big Numbers
DONE 2007.12.02 PROB Buy Low, Buy Lower [ANALYSIS]
Section 4.3 DONE 2008.03.05 PROB The Primes [ANALYSIS]
DONE 2008.03.07 PROB Street Race [ANALYSIS]
DONE 2008.03.07 PROB Letter Game [ANALYSIS]
DONE 2008.03.07 PROB Shuttle Puzzle [ANALYSIS]
Section 4.4 DONE 2008.03.08 PROB Pollutant Control [ANALYSIS]
DONE 2008.03.09 PROB Frame Up [ANALYSIS]
 
Section 5.1 DONE 2008.03.14 TEXT Convex Hulls
Usaco 总结  lzoi leokan  http://hi.baidu.com/leokan 

DONE 2008.03.11 PROB Fencing the Cows [ANALYSIS]


DONE 2008.03.14 PROB Starry Night [ANALYSIS]
DONE 2008.03.15 PROB Musical Themes [ANALYSIS]
DONE 2008.03.16 PROB Snail Trail [ANALYSIS]
Section 5.2 DONE 2008.03.16 PROB Electric Fences [ANALYSIS]
DONE 2008.03.17 PROB Wisconsin Squares [ANALYSIS]
DONE 2008.03.19 TEXT Heuristics & Approximate Searches
DONE 2008.03.20 PROB Milk Measuring [ANALYSIS]
Section 5.3 DONE 2008.03.21 PROB Window Area [ANALYSIS]
DONE 2008.03.22 PROB Network of Schools [ANALYSIS]
DONE 2008.03.22 PROB Big Barn [ANALYSIS]
DONE 2008.03.23 PROB All Latin Squares [ANALYSIS]
DONE 2008.03.25 PROB Canada Tour [ANALYSIS]
Section 5.4 DONE 2008.04.04 PROB Character Recognition [ANALYSIS]
DONE 2008.03.28 PROB Betsy's Tour [ANALYSIS]
DONE 2008.03.29 PROB TeleCowmunication [ANALYSIS]
DONE 2008.03.30 PROB Picture [ANALYSIS]
Section 5.5 DONE 2008.03.30 PROB Hidden Passwords [ANALYSIS]
DONE 2008.04.04 PROB Two Five [ANALYSIS]
 
DONE 2008.04.01 PROB Postal Vans [ANALYSIS]
Section 6.1 DONE 2008.04.02 PROB A Rectangular Barn [ANALYSIS]
DONE 2008.04.03 PROB Cow XOR [ANALYSIS]
 
 
Usaco 总结  lzoi leokan  http://hi.baidu.com/leokan 

附录二:我写得比较详细的题解 
USACO 3.1.4 Shaping Regions
阅读了资料:薛矛的集训队论文
参考了的方法:《信息学奥林匹克竞赛典型试题剖析》中的 noi 97 年卫星覆盖
解法,卫星覆盖是立体的立方体覆盖,它的退化就是矩形覆盖。

我用的方法是,由底层的矩形开始,向上层搜索是否有重复的部分,如果有重复
的部分就将这个矩形分割,然后将没重复的部分继续向上搜索,当搜索到顶层后
剩下的矩形就是这种颜色的面积。设有 n 个矩形,这种方法最坏的情况下复杂度
会达到(n^3)但是我提交之前本来想着会不通过,但是不但过了,且每个点的时间
都在 0.02 秒以下,这说明了此方法虽然理论上最坏情况下复杂度高,但是在平均
情况下复杂度不会很高.

解题报告

问题描述:

N 个不同的颜色的不透明的长方形(1 <= N <= 1000)被放置在一张宽为 A 长为 B


的白纸上。
这些长方形被放置时,保证了它们的边于白纸的边缘平行。
所有的长方形都放置在白纸内,所以我们会看到不同形状的各种颜色。
坐标系统的原点(0,0)设在这张白纸的左下角,而坐标轴则平行于边缘。
求俯视能看到的颜色和该颜色的面积.

问题分析:

这个问题可以模拟,但是模拟有很多办法.
1.染色,给每个放入的矩形在白纸染色
2.线段树的扩展矩形树
3.矩形切割
等等

这里讨论矩形切割的算法

条件假设:
题目条件
矩形的边于白纸的边缘平行。
所有的矩形都放置在白纸内
坐标系统的原点(0,0)设在这张白纸的左下角,而坐标轴则平行于边缘。
Usaco 总结  lzoi leokan  http://hi.baidu.com/leokan 

模型的建立
假设两个矩形有重复部分,且 A 在 B 的上面,则 B 可以被看见的部分是 B-B∩A.
这个 B-B∩A,的部分不一定是一个矩形,那么我们可以将它变为矩形.
这样就得到三个矩形.
假设 n 个矩形都有重复部分,也可以逐个按此方法进行分解.

符号及变量说明
用 oblong[i]来表示矩形 i,它含有 5 个量
llx,lly,urx,ury,colour,分别表示左下角 x 轴坐标,左下角 y 轴坐标,右上角 x
轴坐标,右上角 x 轴坐标.

模型的求解
当一个矩形 oblong[i]和 oblong[j]重复,且 j 在 i 的上方时,可以将矩形 i 这样
分解.
若 oblong[j].llx>oblong[i].llx,则新产生的矩形
oblong[new].urx:=oblong[j].llx,就是分割出原矩形以两矩形相交的位置向左
的部分.
若 oblong[j].urx<oblong[i].urx,则新产生的矩形
oblong[new].llx:=oblong[j].urx,就是分割出原矩形以两矩形相交的位置向右
的部分.
这样原矩形就剩下 oblong[j].llx 和 oblong[j].urx 中间的部分了.
若 oblong[j].lly>oblong[i].lly,则新产生的矩形
oblong[new].ury:=oblong[j].lly,就是分割出原矩形以两矩形相交的位置向下
的部分.
若 oblong[j].ury<oblong[i].ury,则新产生的矩形
oblong[new].lly:=oblong[j].ury,就是分割出原矩形以两矩形相交的位置向上
的部分.
如此将一个矩形分割,可以利用一个递归的过程求解问题.
Usaco 总结  lzoi leokan  http://hi.baidu.com/leokan 

编程解决:
procedure cover(obnew:obtype;floor:integer);{obtype 类型如上文所述}
var
obtemp:obtype;
begin
while (floor<=n) and
((oblong[floor].llx>=obnew.urx)or(oblong[floor].lly>=obnew.ury)or(obl
ong[floor].urx<=obnew.llx)or

(oblong[floor].ury<=obnew.lly)) do inc(floor);
if floor>n then
begin
inc(ans[obnew.colour],abs((obnew.urx-obnew.llx)*(obnew.ur
y-obnew.lly)));
exit;
end;
if oblong[floor].llx>obnew.llx then
begin
obtemp:=obnew;
obtemp.urx:=oblong[floor].llx;
Usaco 总结  lzoi leokan  http://hi.baidu.com/leokan 

cover(obtemp,floor+1);
obnew.llx:=oblong[floor].llx;
end;
if oblong[floor].urx<obnew.urx then
begin
obtemp:=obnew;
obtemp.llx:=oblong[floor].urx;
cover(obtemp,floor+1);
obnew.urx:=oblong[floor].urx;
end;
if oblong[floor].lly>obnew.lly then
begin
obtemp:=obnew;
obtemp.ury:=oblong[floor].lly;
cover(obtemp,floor+1);
end;
if oblong[floor].ury<obnew.ury then
begin
obtemp:=obnew;
obtemp.lly:=oblong[floor].ury;
cover(obtemp,floor+1);
end;
end;

USACO 3.4.1 Closed Fences


算法主要是用了向量的运算(知道有计算几何的题目预先准备了几天数学,把向
量空间,矩阵之类的都预习了...)

首先向量积的数值是不同于数量积的,但是我们在运用计算几何实际上对向量的
方向这个角度并不在乎,所以就取数值
(以下提到的 ab 都是向量)
a * b=|a|*|b|*sinθ
这和数量积的
a * b=|a|*|b|*cosθ 很相似
实际上向量积就是一个矩阵的行列式符号的运算,将向量分解,起点移到原点得
分量 a1i,b1j,a2i,a2j
a * b 就是
|i j |
|a1 b1|
|a2 b2|
a1*b2-b1*a2

不必移到原点的通式:(p1 - p0) × (p2 - p0) = (x1 - x0)(y2 - y0) - (x2 -


x0)(y1 - y0).
Usaco 总结  lzoi leokan  http://hi.baidu.com/leokan 

左右手螺旋:
图片:

左右手螺旋不是看一条线在另一条线的左边还是右边,事实上恰恰相反,a 在 b 的
左边它是通过右手螺旋得到的.
结合前面说的向量积,a*b,如果 a,b 成左手系时 θ 角是负数,所以 a*b 是一个负
数,而它成右手系时 a*b 是一个正数.
通过这个就可以判断一个点在另一个向量的左边还是右边.θ=0 时两向量平行,
所以他们的积为 0.

两线段相交:
快速排斥实验
图片

以两个线段为对角线做两个矩形,两个矩形有相交才通过快速排斥实验
Usaco 总结  lzoi leokan  http://hi.baidu.com/leokan 

跨立实验:

介绍文字见图片内容

代码:
function multi(p1,p2,p0:xy):real;{计算向量积}
begin
exit((p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y));
end;
function maxof2(x,y:real):real;
begin
if x>y then exit(x)
else exit(y);
end;
function minof2(x,y:real):real;
begin
if x>y then exit(y)
else exit(x);
end;
function cut(u,v:line):boolean;
begin
if maxof2(u.a.x,u.b.x)<minof2(v.a.x,v.b.x) then exit(false);{快速
排斥实验}
if maxof2(v.a.x,v.b.x)<minof2(u.a.x,u.b.x) then exit(false);{快速
排斥实验}
if maxof2(u.a.y,u.b.y)<minof2(v.a.y,v.b.y) then exit(false);{快速
排斥实验}
Usaco 总结  lzoi leokan  http://hi.baidu.com/leokan 

if maxof2(v.a.y,v.b.y)<minof2(u.a.y,u.b.y) then exit(false);{快速


排斥实验}
if multi(v.a,u.b,u.a)*multi(u.b,v.b,u.a)<=0 then exit(false);{跨立
实验}
if multi(u.a,v.b,v.a)*multi(v.b,u.b,v.a)<=0 then exit(false);{跨立
实验}
exit(true);{通过}
end;

有了判断线段是否相交的函数做这题就简单了
对于问题一,判断是否有 fence 相交即可,枚举一次
对于问题二:
这里感谢一个师兄,他的日志给了我帮助.
用二分的思想判断一条线段是否能看到,
取一条线段的端点 A,B,以及它的中电 C.人的位置是 O
不能看到的条件:
1.AO 和 BO 被同一条边遮挡
2.AO,BO,CO 均被遮挡
3.AB 的长度接近为 0(看成一个质点)
能被看到的条件:
4.除了端点能有一点未被遮挡
5.当上述两个条件未达到时用二分的方法,将此线段割为两块,重复上述过程.

代码:{其中 cut1 为端点相交不算相交的相交判断函数,cut2 端点相交算相交}


function see(v:line):boolean;
var
i:integer;
ao,bo,co,temp:line;
sa,sb,sc:boolean;
begin
if len(v)<0.01 then exit(false);{条件 3}
ao.a:=v.a;
ao.b:=o;
bo.a:=v.b;
bo.b:=o;
co.a:=middle(v);{取中点}
co.b:=o;
sa:=true;{未被遮挡}
sb:=true;{未被遮挡}
sc:=true;{未被遮挡}
for i:=1 to n do
if not used[i] then{use 使它不会重复判断自己}
begin
temp.a:=corner[i];
Usaco 总结  lzoi leokan  http://hi.baidu.com/leokan 

if i=n then temp.b:=corner[1]


else temp.b:=corner[i+1];
if cut2(ao,temp) and cut2(bo,temp) then exit(false);{条
件 1}
sa:=sa and not cut1(ao,temp);
sb:=sb and not cut1(bo,temp);
sc:=sc and not cut2(co,temp);
end;
if sc then exit(true);{条件 4}
if (not sa) and (not sb) and (not sc) then exit(false);{条件 2}
if sa then{若 CA 边未被遮挡}
with temp do
begin
temp.a:=v.a;
temp.b:=co.a;
end;
if see(temp) then exit(true);{5,二分递归}
if sb then{若 CB 边未被遮挡}
with temp do
begin
temp.a:=v.b;
temp.b:=co.a;
end;
if see(temp) then exit(true){5,二分递归}
else exit(false);
end;

USACO 3.1.2 Score Inflation 
 
问题重述: 
给出自然数 m 和 n,以及 n 对数. 
由第 1 对数开始到第 n 对数为止 
记第 x 对数的两个数为 S(x),T(x). 
要求一种取数对的方法,使得在∑T<=m 的情况下∑S 最大.(每对数可以重复取),输出∑S 的最
大值. 
 
问题分析: 
既然每对数可以取任意多次,那么假如挑 S 最大的数对取是否可以呢?显然不行,S 大的数
对有可能 T 也大,这样不能保证在∑T<m 的情况下取得∑S 的 
 
最大显然取 T 小的数对也不能保证满足条件. 
而挑 S/T 最大的取是否可以呢?这种方法在不要求最优解的情况下是可行的,但是我们现
在要求的是最优解,假设有一种情况是 S(1)/T(1)=100,S 
Usaco 总结  lzoi leokan  http://hi.baidu.com/leokan 

 
(2)/T(2)=99,但是 2T(1)>m,T(1)+T(2)>m,不过 2T(2)<m,此时显然取 T(2),S(2)好过取 T(1),S(1). 
总之,既不能只考虑 T,S 的大小,也不能简单地用 T,S 的关系来估价,而要采用全面的分析. 
假设枚举各种取法,那么用计算机编程实现的话时间复杂度将达到 O(m^n).这是不能接受
的. 
可以观察到,取多一次数对 S(x),T(x),与不取这个数对 S(x),T(x),的∑S,∑T 有一种联系,可以考
虑用动态规划求解. 
 
条件假设: 
题目条件,每对数可以重复使用. 
 
符号及变量说明: 
记 f(x)表示当∑T=x 时的∑S 
 
模型的建立: 
设已经得到一种取数方法,取得一种状态∑S1,∑T1,那么此时如果再取 Tx,Sx,那么设新的状
态是∑S2,∑T2,这里有∑S2=∑S1+Sx,∑T2=∑T1+Tx.这是状态∑S2,∑T2 的一种得到方法.考虑当
∑T2 等于一个数 Tm 时,设∑S2 的值是可变的,那么∑S2 可以由若干个(∑Si,∑Ti,∑Ti<∑T2)状态
的其 
 
中一种状态得到. 
用符号表达就是,f(x)=f(x‐Ti)+Si. 
既然我们需要取得最大值,就枚举每一个满足条件的状态. 
f(x)=max{f(x‐Ti)+Si}    (1<i<n,且 Ti<x) 
 
模型的求解: 
方法一:直接建立模型 
score:array[1..n]←S 
timearray[1..n]←T 
f:array[1..m]←0  {f[x]=f(x)} 
for i←1 to m do 
  for j←1 to n do  {f(x)=max{f(x‐Ti)+Si}   
    if f[i‐time[j]]+score[j]>f[i] and i‐time[j]>0 
      then f[i]←f[i‐time[j]]+score[j] 
这种方法是可行的方法之一,但是效率不高,还有一种方法 
方法二:充分利用已经得到的状态 
f:array[1..m]←(f[i]=Si) 
for i←1 to m do 
  for j←1 to i div 2 do 
    if f[i‐j]+f[j]>f[i] then f[i]:=f[i‐j]+f[j]; 
这种方法直接利用以前得到的每一种状态∑Si,∑Ti 求解,将状态相加,而不是将 Si,Ti 相加,可
以说效率会更高.    
 

USACO 3.3.5 A Game   
Usaco 总结  lzoi leokan  http://hi.baidu.com/leokan 

问题描述: 
给出一个有 n 个数序列 Q1,Q2,Q3...Qn,做一个博弈问题. 
两人轮流重序列的两端取走一个数,在第二个人以最佳策略取数的情况下求第一个人取
数的和的最大值. 
 
问题分析: 
两个人都以最佳策略取数,那么这个最佳策略就是一个一个最优解,考虑有 n‐2 个数的序
列,它的最优解为 x,给这个序列再加上 2 个数,Qn‐1,Qn,取这两个数的较大者加上 x,就是一
个新的最优解.反过来说,每个最优解,它减去序列中的一个数,都是另一种情况的最优解,
所以最优子结构得证.一个最优解可以加上数变成新的最优解,所以重叠子问题得证.可以
用动态规划求解. 
 
符号及变量说明: 
记 Q 为数的序列,Qi 为序列中第 i 个数. 
记 sum(i,j)为序列中第 i 个数到第 j 个数的和. 
记 f(i,j)为序列中由 i 开始到第 j 个数按照游戏规则能取得到的最大值. 
 
模型的建立: 
设得到一个子序列 Qi,Qi+1,Qi+2,...,Qj‐2,Qj‐1,Qj; 
由于后一个人按最佳策略取数,所以他必将取一个最大值 f(i+1,j)或 f(i,j‐1),那么此时取数
的人以后取得的数将是 sum(i+1,j)‐f(i+1,j)或是 sum(i,j‐1)‐f(i,j‐1),此时取数的人按最佳策略
取数,他会取 Qi 或者 Qj 使得 sum(i+1,j)‐f(i+1,j)+Qi 和 sum(i,j‐1)‐f(i,j‐1)+Qj 二者能有较大值.
这样从游戏的结束向游戏的开始推,可以得到总的最优解. 
 
模型的求解: 
显然,f(i,i)=sum(i,i)=Qi;这可以作为边界条件. 
 
for i←n‐1 downto 1 do 
  for j←i+1 to n do 
    begin 
      sum(i,j)←sum(i,j‐1)+Qj 
      f[i,j]←max{sum(i+1,j)+Qi‐f(i+1,j),sum(i,j‐1)+Qj‐f(i,j‐1)} 
    end; 
 

USACO 2.2.4 Money Systems


问题重述:

给出 v,n,和 v 个互不相同的数字,求用 v 个互不相同的数字累加得 n 这个数字(数字可以

重复使用)的方法总数.

问题分析:

依照题意得到,累加 x 这个数组成数字 y 的方法集合 A,和不累加 x 这个数组成数字 y-x


Usaco 总结  lzoi leokan  http://hi.baidu.com/leokan 

的方法集合 B 有一种映射关系,f:A→B.f 就是在 A 中某一种累加方法减去 x.既然有这种

关系,那么我们定义 f(x)为用这些数累加得 x 的方法总数,cash[i]表示第 i 个数,我们可

以说 f(x)=∑f(x-cash[i])(i∈{1,2...v}.可以用动态规划求解.

编程解决:

边界条件设 f[0]等于 1,什么累加的方法数是一,累加得 0.

f[0]←1;

for i←1 to v do

for j←cash[i] to n do

f[j]←f[j]+f[j-cash[i]]
 

USACO 2.3.2 Cow Pedigrees 
 
问题重述: 
给出 n,k,求满足一下条件的二叉树个数 
1.每个结点的度为偶数 
2.该树有 n 个结点 
3.该数的深度为 k 
 
问题分析: 
用动态规划和乘法原理求解,可以观察到一个树 G(有 x 个结点,深度为 k),如果去除它的根
结点可以得到两个子数 G1,G2,这两个子图的深度为 k‐1,他们的结点数的和为 x‐1.设其中
G1 有 i 个结点则 G2 有 x‐1‐i 个结点. 
 
定义 P(G)为与满足条件的二叉树 G 有同样多结点有深度相同且同样满足条件的树的个
数. 
 
将二叉树按上述方法依次分解为(有 1 个结点,深度为 k‐1 的树和有 x‐1‐1 个结点深度为 k‐1
的树),(有 2 个结点,深度为 k‐1 的树和有 x‐1‐2 个结点深度为 k‐1 的树),(有 3 个结点,深度
为 k‐1 的树和有 x‐1‐3 个结点深度为 k‐1 的树)...(有 x‐1‐1 个结点,深度为 k‐1 的树和有 1 个
结点深度为 k‐1 的树)... 
 
由乘法原理得到:由 G 按上述方法分解成的每对二叉树(Gx,Gy)加一个根结点构成的二叉
树的个数有 P(Gx)*P(Gy)个. 
 
G 可以分解为 x‐2 对子树,由加法原理得到 P(G)=∑P(Gi)*P(Gj){(i,j)∈G 可以分解到的子树对
(Gi,Gj)} 
 
Usaco 总结  lzoi leokan  http://hi.baidu.com/leokan 

定义 f(x,k)满足为深度为 k,结点个数为 x,每个结点的度为偶数的二叉树的个数,由上述分


析得到 f(x,k)=∑(f(x‐1‐i,k‐1)*f(i,k‐1){1<=i<=x‐2}. 
由USACO 3.2.4 Feed
Ratios展开的关于信息学
竞赛的解方程使用
矩阵行列式相关运算

LZOI 刘锴 制作
题目引入
USACO 3.2.4 Feed Ratios
• 农夫约翰从来只用调配得最好的饲料来为他的奶牛。饲料用三种原料调配
成:大麦,燕麦和小麦。他知道自己的饲料精确的配比,在市场上是买不
到这样的饲料的。他只好购买其他三种混合饲料(同样都由三种麦子组
成),然后将它们混合,来调配他的完美饲料。
给出三组整数,表示 大麦:燕麦:小麦 的比例,找出用这三种饲料调配
x:y:z的饲料的方法。
例如,给出目标饲料 3:4:5 和三种饲料的比例:1:2:3
3:7:1
2:1:2
你必须编程找出使这三种饲料用量最少的方案,要是不能用这三种饲料调
配目标饲料,输出“NONE”。“用量最少”意味着三种饲料的用量(整
数)的和必须最小。
对于上面的例子,你可以用8份饲料1,2份饲料2,和5份饲料3,来得到7
份目标饲料:
8*(1:2:3) + 1*(3:7:1) + 5*(2:1:2) = (21:28:35) = 7*(3:4:5)
表示饲料比例的整数,都是小于100(数量级)的非负整数。表
示各种饲料的份数的整数,都小于100。一种混合物的比例不会由其他混
合物的比例直接向加得到。
题目重述
• 对于给出的
• a1:a2:a3
b1:b2:b3
c1:c2:c3
• 和d1,d2,d3
• 求x,y,z使得(a1*x+b1*y+c1*z):
(a2*x+b2*y+c2*z):(a3*x+b3*y+c3*z)
=d1:d2:d3
• 且
a1*x+b1*y+c1+a2*x+b2*y+c2*z+a3*x+b3
*y+c3*z最小
用矩阵表示
=

换一种表示方法
=
克莱姆法则
下面讲如何用行列式与克莱
姆法则解这个方程从而解决
这道题
线性方程组的概念
n个未知变元、n个方程组成的线性方程组为
a11 x1+ a12 x2+……+ a1n xn = b1
a21 x1+ a22 x2+……+ a2n xn = b2
………
an1 x1+ an2 x2+……+ ann xn =bn (1)
n
即 ∑aijxj=bi i=1,2,…n
j=1
方程组的解
有解和无解--若有一组数 x10,x20,…xn0 代替(1)中的x1 ,x2 ,…xn ,使(1)中
每个等式成立,则称方程组(1)有解(亦称(1)是相容的)
x10 , x20,… xn0 为方程组(1)的一组解;
否则,称(1)无解(不相容)
唯一解和多解--若(1)仅有一组解,则称(1)有唯一解,如果有多于
一组解,则称(1)有多 解。
n 阶行列式
一、二阶、三阶行列式
引例:设方程组 a1x+b1y=k1
a2x+b 2y=k2 有唯一解
用消元法解得 k1 b1
x= k1b2 –k2 b1= k2 b2
a1b2 –a2 b1 a1 b1
a2 b2 二阶行
称为
列式的引入,
二阶 a1 k1
a2 k2 使二元线性
行列式 a1k2 –a2 k1
Y= = 方程组的解
a1b2 –a2 b1 a1 b1
a2 b2 的表达简洁、
定义: a b = a d – b c 易记
c d

例: 2 5
= 2×4 – 5×(-3)=23
-3 4
三阶行列式的定义
a11 a12 a13
= a11a22a33 + a 12a 23a31 + a 13a 21a32
a21 a22 a23
- a13a22a31 - a 12a 21a33 - a 11a 23a32
a31 a32 a33
三阶行列式,可以表示三
元线性`方程组的解
1 2 3
例: = 1×2×3 + 2×0×2 + 3×(-1)(-2)
-1 3 0 - 3×3×2 - 2 (-1)×2 - 1×(-2)×0
2 -2 2 =-2 下面,把三阶行列式的
定义推广到 n 阶
行列式性质
性质1 行列式中行列元素互换, 行列式不变
a11 a12 … a1n a11 a21 … an1
即 a21 a22 … a2n a12 a22 … a2n
…… =
……
an1 an2 … ann a1n a2n … ann 行列式中行
列地位对称,
凡是对行成
立的性质,
称行列式的
转置 对列也成立。
性质2 互换行列式的两行,行列式变号
a11 a12 … a1n a11 a12 … a1n
… …
i ai1 ai2 … ain ri rj aj1 aj2 … ajn i
互换 i 、j两行 …… === - ……
a
j j1 a … a ai1 ai2 … ain j
… j2 jn

an1 an2 … ann an1 an2 … ann
性质3:行列式中某行有公因子k, 则可提到行列式号外
a11 a12 … a1n a11 a12 … a1n
…… ri (1/k) ……
kai1 kai2 … kain ai1 ai2 … ain
…… = k ……
an1 an2 … ann an1 an2 … ann

性质4:行列式中两行成比例,则该行列式为零

a11 a12 … a1n a11 a12 … a1n


证明 … …
ai1 ai2 … ain ai1 ai2 … ain
…… ……
kai1 kai2 … kain =k ai1 ai2 … ain = 0
… …
an1 an2 … ann an1 an2 … ann
性质5:行列式的某行(列)元素为两数之和,则行列

可分为下两行列式之和
a11 a12 … a1n a11 a12 … a1n a11 a12 … a1n
….. ….. …..
ci1+di1 ci2 +di2 … cin+din = ci1 ci2 … cin di1 di2 … din
+
…… …… ……
an1 an2 … ann an1 an2 … ann an1 an2 … ann

性质6:行列式中某一行乘以同一元素加到另一行,
行列式不变
a11 a12 … a1n a…11 a12 … a1n

ai1 ai2 … ain ri+k r j i ai1+kaj1 ai2 +kaj2 … ain +kajn
△(aij)= …… = ……
aj1 aj2 … ajn aj1 aj2 … ajn
… …
an1 an2 … ann
an1 an2 … ann
a11 a12 a13 行列式按行(列)展开
= a11a22a33+ a 12a 23a31+a 13a 21a32
a21 a22 a23
- a13a22a31 - a 12a 21a33 - a 11a 23a32
a31 a32 a33

=a11(a22a33- a 23a32) –
a12 (a 21a33 - a 23a31 ) + a13(a 21a32-a22a31 )
a22 a23 - a a21 a23 a21 a22
=a11
a32 a33 12
a31 a33 + a13 a31 a32
=a11M11 - a12M12+a13M13 = a11A11 + a12A12+a13A13
例: 3 1 -1 2
-5 1 3 -4
2 0 1 -1
1 -5 3 -3 13 -11 2-1 2
元素 a21的余子式为M21= 0-5 11 -13 -4
-52 3 0 -31
1-1 -1 2
1 -5 2+13 0 -3 1 -1
元素 a21的代数余子式为A21=(-1)
-5 3 -3
类似,可以计算 C2+C3 1 1 2
任意 M ij =-1 1
0 0-1 -12
Aij 0 10 -3
-5 -1
i=1,2…4 -5 3 1+2 -3
j=1,2…4 = -1× 1 (-1) [-(-1)(-5)]
=-5
D= a11A11 + a12A12+a13A13
由四阶行列式展开: + a14A14
从而可以计算四阶行列式,类
似可以计算五阶行列式
克莱姆法则 (1)

n
克莱姆法则: 如果线性方程组 ∑ aij xj=bi i=1,2…,n
j=1
a11 a12 … a1n
a21 a22 … a2n
的系数行列式D= ≠0,
……
an1 an2 … ann
则方程组有唯一解 x j =Dj / D , j=1,2,…n
b1
b2
其中Dj是由 : 代替D中第j 列得到的行列式.
bn
a11... b1 … a1n
Dj= a21… b2 … a2n
……
an1… bn … ann
第 j列
• 这样子就得到解这个方程的方法,再也不
用枚举判断是否符合了

• 整体解题思路,由小到大枚举d1,d2,d3的
倍数,解这个方程,判断解是否为整数.
程序
• function determinant(temp:matrix):longint;{计算
三阶行列式}
var
num:longint;
begin
num:=temp[1,1]*temp[2,2]*temp[3,3]+
temp[1,3]*temp[2,1]*temp[3,2]+
temp[1,2]*temp[2,3]*temp[3,1]-
temp[1,3]*temp[2,2]*temp[3,1]-
temp[1,2]*temp[2,1]*temp[3,3]-
temp[1,1]*temp[2,3]*temp[3,2];
exit(num);
end;
• procedure work;
var
d,i,j,k:longint;
dd:array[1..3] of longint;
temp:matrix;
begin
d:=determinant(feed);
if d=0 then{若行列式为0必然无解}
begin
writeln('NONE');
close(output);
exit;
end;
• for i:=1 to 100 do{枚举d1,d2,d3的倍数}
begin
for j:=1 to 3 do
begin
temp:=feed;
for k:=1 to 3 do
temp[k,j]:=goal[k]*i;{替换列}
dd[j]:=determinant(temp);{计算行列式}
end;
if dd[1] mod d<>0 then continue;
if dd[2] mod d<>0 then continue;
if dd[3] mod d<>0 then continue;
if dd[1] div d<0 then continue;
if dd[2] div d<0 then continue;
if dd[3] div d<0 then continue;
writeln(dd[1] div d,' ',dd[2] div d,' ',dd[3] div
d,' ',i);
exit;
end;
writeln('NONE');
end;
谢谢

LZOI 刘锴

You might also like