【比赛链接】:click here~~
uva 12435 C. Consistent Verdicts
【题目大意】:给你二维平面一些人的坐标,每个人手上都有一把枪,求全部人同时开枪后所有人听到枪声的次数的可能数目。
【解题思路】:O(n^2)暴力枚举+unique 函数去重相邻元素。居然只跑了3ms,~~
代码:
uva 12439 G. February 29
【题目大意】两个日期之间求leap data的个数:ps:常规方法判断会TE,因此换个思路,判断闰年可以用除法
代码:
uva 12442 J. Forwarding Emails
【题目大意】:酋长发一封信给部落的人,给出部落的人的关系,没人只能收一次且发一次,求在信能传递的最长的的人数链的情况下第一次收到信的人的编号
【解题思路】:
网上看到一个比较直观的思路过程,复制过来,便于理解:
Solution Description :
DFS problem
Read this line carefully in problem description - "they each pick one other person they know to email those things to every time - exactly one, no less, no more (and never themselves)"
i.e Each person send email only one. For each person has only one adjacency person. The input can not be (1 to 3, 2 to 3, 1 to 2) , because for person 1 here 2 adjacency person 3 and 2.
So, you can represent this graph using one dimensional array adj[N].
Do not need to stack, you can use recursion.
Example:
visit[1] | visit[2] | visit[3] | visit[4] |
False | False | False | False |
visit[1] | visit[2] | visit[3] | visit[4] |
True | True | False | False |
And count_visited_node=2 (1->2)
visit[1] | visit[2] | visit[3] | visit[4] |
True | True | True | False |
And count_visited_node=3 (3->2->1)
visit[1] | visit[2] | visit[3] | visit[4] |
True | True | True | True |
And count_visited_node=4 (4->3->2->1)
代码:
几组数据: