1 / 48
文档名称:

赛题分析.ppt

格式:ppt   页数:48页
下载后只包含 1 个 PPT 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

赛题分析.ppt

上传人:yixingmaoj 2016/7/12 文件大小:0 KB

下载得到文件列表

赛题分析.ppt

相关文档

文档介绍

文档介绍:Problem G Toward Zero ? Time Limit: 1 second ? Memory Limit: 32,768 KB Description ? Have you ever heard of this game? The player jumps in a special game board under certain rules, so that the numbers he jumps on, after being linked up by plus or minus signs, get closest to zero. ? The game board looks like the one shown in Figure . Its size is determined by the number of squares in the middle row N. (Figure is an example where N = 4.) The player starts at the bottom-most square, then jumps in any of the directions shown in Figure . The game ends when the player reaches the topmost square. During the game, the player cannot jump out of the game board. Finally we write down the 2N-1 numbers in order, then insert plus or minus signs between each pair of adjoining numbers such that the result is closest to zero. ? Let us look at the game board in Figure as a example. We should get: 7+8+(-5)+(-2)-5-1-2=0, 7+10+(-7)-6+(-3)-3+2=0, 7+10+(-5)-10- 5+1+2=0, or 7+10+(-5)+(-2)-5-3-2=0. Input ?The first line of input contains N (1 ≤ N ≤ 30). The following 2N-1 lines give the numbers in the squares in the game board. The j- th number in the (i+1)- th line corresponds to the j- th number in the i- th row of the game board. (The numbers are all ≥-50 and ≤ 50.) ? Input contains multiple test cases, and it ends with a case where N = 0. Output ? For each case, your output should print the absolute value of the result you get for each game board. Sample Input ?4?2?3 1 ?-3 5 7 ?6 10 -2 20 ?-7 -5 -8 ?10 8 ?7 ?0 Sample Output ?0目标:零?时间限制:1S?内存限制:36728 K 描述?听说过这种游戏吗?游戏者按规则在特殊棋盘跳动, 将跳过的数字用加或减连起来,使得尽量接近零。?棋盘如图,大小是中间行的方块数 N( 图中 N = 4 )。游戏者从底下开始,如图示方向到达最顶端,过程中不得跳出棋盘。最后把 2 N-1 个数依次写下, 在其中插入“+”或“-”,使结果接近零。?如图为例,我们可以计算如下路径: 7+8+(-5)+(-2)-5- 1-2=0, 7+10+(-7)-6+(-3)-3+2=0, 7+10+(-5)-10-5+1+2=0, or 7+10+(-5)+(-2)-5-3-2=0. 输入第一行是 N (1 ≤ N ≤ 30) 。下面 2N-1