思路难以想到问题和需要注意条件

设计足球比赛场

Q:You need to organize a football tournament. There are n teams given. You need to prepare a schedule for the matches so that each team plays with every other team and on the same day no team plays twice. You want to finish the tournament as early as possible.

有一个很简单的方法:把n个team放在一个正n边形的n个点上,假设第一天1和2要比赛,那么在1和2之间连一条直线,于是第一天剩下的比赛对应的直线都必须和1、2之间的直线平行,共[n/2]场,中括号表示向下取整,不管n的奇偶(若为奇数则有一队第一天不用比)。第二天2和3比,第三天3和4比,一共比n天搞定。

http://www.1point3acres.com/bbs/thread-12962-1-1.html

Re-order data packets

Q:应用程序的re-order的buffer的设计,如果满了可以丢弃.大概是应用程序需要in-order的数据包,但是收到的数据可能是乱序的(类似于IP分片,每一个数据片有一个序列号,但是不同的数据片.到达应用程序的顺序可能和发送的顺序不一样,引起乱序, 但是不会太夸张的乱序,第一个数据包不会跑到第一万个以后)。如何设计算法通过这个buffer.把数据片变成有序。

  • 插入排序,因为包之间相隔距离不远
  • 有人用环形队列做。

最近palindrome

对于一个整数,找最近palindromw

  • 10000情况是9999,而不是10001

results matching ""

    No results matching ""