现在的位置: 首页 > 综合 > 正文

暑期集训队员选拔赛

2013年08月27日 ⁄ 综合 ⁄ 共 4610字 ⁄ 字号 评论关闭

Barn Repair

Time Limit:1000MS  Memory Limit:65536K
Total Submit:63 Accepted:18

Description

It was a dark and stormy night that ripped the roof and gates off the stalls that hold Farmer John's cows. Happily, many of the cows were on vacation, so the barn was not completely full.
The cows spend the night in stalls that are arranged adjacent to each other in a long line. Some stalls have cows in them; some do not. All stalls are the same width.
Farmer John must quickly erect new boards in front of the stalls, since the doors were lost. His new lumber supplier will supply him boards of any length he wishes, but the supplier can only deliver a small number of total boards. Farmer John wishes to minimize the total length of the boards he must purchase.
Given M (1 ≤ M ≤50), the maximum number of boards that can be purchased; S (1 ≤ S ≤ 200), the total number of stalls; C (1 ≤ C ≤ S) the number of cows in the stalls, and the C occupied stall numbers (1 ≤ stall_number ≤ S), calculate the minimum number of stalls that must be blocked in order to block all the stalls that have cows in them.
Print your answer as the total number of stalls blocked.

Input

There several test cases, for each test case:
Line 1: M, S, and C (space separated)
Lines 2-C+1: Each line contains one integer, the number of an occupied stall.

Output

A single line with one integer that represents the total number of stalls blocked.

Sample Input

4 50 18
3
4
6
8
14
15
16
17
21
25
26
27
30
31
40
41
42
43

 

Sample Output

25

Pascal's Triangle of Death

Time Limit:1000MS  Memory Limit:65536K
Total Submit:61 Accepted:17

Description

In this problem, you are asked to generate Pascal's Triangle. Pascal's Triangle is useful in many areas from probability to polynomials to programming contests. It is a triangle of integers with ``1'' on top and down the sides. Any number in the interior equals the sum of the two numbers above it. For example, here are the first 5 rows of the triangle.
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
In ``Pascal's Triangle of Death,'' you are to generate a left justified Pascal's Triangle. When any number in the triangle is exceeds or equals 1060, your program should finish printing the current row and exit. The output should have each row of the triangle on a separate line with one space between each element.
The final element of each line should be directly followed by a newline. There is no space after the last number on each line.

Input

There is no input for this problem.

Output

 

Sample Input

 

Sample Output

1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
.
.
.
etc.

 

Source

UVa

 

 

 

 

 

迷宫

Time Limit:1000MS  Memory Limit:65536K
Total Submit:35 Accepted:16

Description

一天,birdfly遇到了上帝,上帝说:“现在我要考验你,天下有一迷宫。此迷宫呈正方形,迷宫被墙分成很多相同的单元房。每两个相邻的单元房都有一个门,现在我把你送入坐标为(1, 1)的房间内,你要走到坐标为(n, n)的房间去,每个房间里都被赋予一个运气值k,如果为正数,表示你会得到相应的金币数,如果为0表示你不得不亏,如果是负数表示你要失去相应的金币数。”上帝正准备走,迟疑了一下补充道:“记住,每个房间只能走一次。”说完,匆匆离去。birdfly一想,如果相邻的房子里有最多的金币也不一定要进去,因为进去了又不能再回到刚才的房间,如果那个房间旁边里运气值都为负数,那就可能要失去更多金币。所以,现在他想请你帮帮忙,他不贪心,他不打算得到一些金币,但他也不想失去,所以他想知道有没有可能到达(n, n)这个房间的时候,不得也不失。注意: (1, 1)和(n, n)这两个位置的运气值也得加上,因为它毕竟到过这两个个房间;不得也不失,即为总的运气值的和为0。呵呵,加油啊!他很期待你的帮助!

Input

多组测试实例。每组首先一个整数n (2 ≤ n ≤ 5),表示迷宫的边长,接下来有n行n列个整数,第i行第j列的整数vij表示坐标为(i, j)的房间里的运气值为vij( |vij| ≤ 100)

Output

如描述,如果可能不得也不失,输出YES,否者输出NO。

Sample Input

3
2 0 -2
3 4 -4
0 -3 4
2
2 3
-3 4

 

Sample Output

YES
NO

 

Source

Birdfly

抱歉!评论已关闭.