Skip to content

Commit 6aaae7f

Browse files
committed
fix bugs
1 parent 550731c commit 6aaae7f

File tree

4 files changed

+93
-13
lines changed

4 files changed

+93
-13
lines changed

1_Divide_and_Conquer/readme.md

+34
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,40 @@ T(n) = 2T(n/2) + cn
508508
$$
509509
因此总复杂度仍为O(nlogn)
510510

511+
512+
513+
514+
515+
## Problem 7.
516+
517+
> A group of n Ghostbusters is battling n ghosts. Each Ghostbuster is armed with a proton
518+
> pack, which shoots a stream at a ghost, eradicating it. A stream goes in a straight line and terminates when it hits the ghost. The Ghostbusters decide upon the following strategy. They will pair off with the ghosts, forming n Ghostbuster-ghost pairs, and then simultaneously each Ghostbuster will shoot a stream at his chosen ghost. As we all know, it is very dangerous to let streams cross, and so the Ghostbusters must choose pairings for which no streams will cross. Assume that the position of each Ghostbuster and each ghost is a fixed point in the plane and that no three positions are collinear.
519+
>
520+
> 1. Argue that there exists a line passing through one Ghostbuster and one ghost such the number of Ghostbusters on one side of the line equals the number of ghosts on the same side. Describe how to nd such a line in O(n log n) time.
521+
> 2. Give an O(n^2^ log n)-time algorithm to pair Ghostbusters with ghosts in such a way that no streams cross.
522+
523+
### 1
524+
525+
我们记Ghostbusters 为平面上红色的点,ghost为平面上黑色的点。
526+
527+
我们首先证明,给定平面上的点,我们能找到一条经过红色和黑色的点,使得在该直线的一侧有等数量的红色点和黑色点。
528+
529+
平面上有n个红点和n个黑点。找到所有2n个点中纵坐标y最小的点。若有两个(因为没有三点共线)点y相同取横坐标x较小的那一个点,记录该点为点A,设A为红色的点(黑色同理,这里以红色为例)。以A点向其余所有的点连线,计算与x轴正向的夹角( [1,0] ),然后按照夹角排序。这样,从x轴正向出发,按照夹角的大小扫描点,初始设置cnt_b = cnt_r=0(黑色和红色的点的个数为0),若当前点是红色,那么cnt_r ++ ,若为黑色,则查看cnt_b 是否等于cnt_r,若相等,该点就是我们要找的分界点。否则cnt_b ++.
530+
531+
由于进行排序,所以复杂度为O(nlogn)
532+
533+
### 2
534+
535+
每一次调用方法一的划分,然后分成两边,对每一边递归即可。
536+
537+
由于每次配对1个,并进行一次排序,因此
538+
$$
539+
T(n) = T(n-1) + nlog(n)
540+
$$
541+
因此复杂度为n^2^logn
542+
543+
544+
511545
## Problem 8.
512546

513547
> The attachedfile Q5.txt contains 100,000 integers between 1 and 100,000 (each row has asingle integer), the order of these integers is random and no integer is repeated.

6_NP/readme.md

+48-1
Original file line numberDiff line numberDiff line change
@@ -169,4 +169,51 @@ mine consistency problem = { \<G,φ> |给定图G以及部分周围地雷个数
169169

170170
![5_false](./img/5_false.png)
171171

172-
因此有 $3SAT \leq_p$Directed Disjoint Paths Problem ,所以Directed Disjoint Paths Problem 是NP完全问题。
172+
因此有 $3SAT \leq_p$Directed Disjoint Paths Problem ,所以Directed Disjoint Paths Problem 是NP完全问题。
173+
174+
175+
176+
177+
178+
## 6. SIP problem
179+
180+
> The set intersection problem (SIP) is de ned as follows: Given finite sets $A_1,A_2,....A_r$,$B_1,B_2,...B_s$ is there a set T such that
181+
> $$
182+
> | T \cap A_i | \ge 1 \quad for \quad i=1,2,....,r
183+
> $$
184+
> and
185+
> $$
186+
> | T \cap B_i | \le 1 \quad for \quad i=1,2,....,s
187+
> $$
188+
> Prove that the SIP is NP-complete.
189+
190+
首先给定集合T, A~i~ ,B~i~, 很容易判断T和各个A~i~, B~i~的交集数是否满足条件,因此SIP问题是NP问题。
191+
192+
为了证明SIP problem是NP完全问题,我们只需要证明 $3SAT \leq_p$SIP problem 问题即可。
193+
194+
对于一个3SAT问题有n个变量m个子句,我们构造A~i~为其各个子句,则共有m个。构造B为空集,T为$\{T_1,T_2.......T_n\}$ , 若3SAT变量$x_i = True$,那么$T_i= x_i$,否则$T_i= \neg x_i$。
195+
196+
显然3SAT有解SIP也有解,3SAT无解,SIP也无解。
197+
198+
199+
200+
201+
202+
203+
204+
205+
206+
207+
208+
209+
210+
211+
212+
213+
214+
215+
216+
217+
218+
219+
Binary file not shown.

readme.md

+11-12
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,32 @@
11
## 算法课题解
22

3-
本题解由hrwhisper 辛苦整理出。
3+
本题解由 **hrwhisper** 辛苦整理出。
4+
每个目录下附带PDF文档,推荐安装 *typora* markdown 编辑器进行阅读。(github的不支持latex差评)
45

56
基本上都已经完成,目前没有完成的题有:
6-
7-
8-
1. Divide and conquer
9-
- 7
10-
2. LP
7+
1. LP
118
- 1,6
129
- 编程题8
13-
3. NF
10+
2. NF
1411
- 6
1512
- 编程题10
16-
4. NP
17-
- 6
1813

1914

2015
有问题或者错误欢迎在issue中提出!
2116
欢迎进行pull request.
22-
转载点名出处
17+
**转载点名出处**
2318

24-
## 支持
2519

26-
觉得好的话可以点击 **star**支持 、**打赏**一点馒头钱=v=
2720

21+
## 支持
2822

23+
觉得好的话可以点击 **star**支持 、**打赏**一点馒头钱=v=
2924

3025
![alipay](./img/alipay.jpg)
3126

3227
![wechat_pay](./img/wechat_pay.png)
3328

29+
##其它可参考的资料
30+
31+
- <a href="./others/卜东波老师算法分析与设计作业答案2015版.pdf" >卜东波老师算法分析与设计作业答案2015版 </a>
32+
- http://bitjoy.net/2016/01/29/algorithm-design-and-analysis-by-dbu/

0 commit comments

Comments
 (0)