繁尘、离梦
(背包特别版见3楼)技能训练营续坑!

本帖最后由 繁尘、离梦 于 2013-4-25 15:05 编辑

技能训练营开坑()

!!!!每题第一个提交的亲并且能通过的亲,我会在结题前,把它的名字mark在题目后方!!!!!10~


最近看了下大家提问的内容,主要是:!27~

算法为主,一些基础知识、习题啊什么的也带着些

既然这样为了活跃社区,特开一个关于编程技能训练的互动帖。!7~

接下来楼主会找很多题目给新手们练习,时不时会更新一楼内容。

2楼是一道题目,一般持续1-2天,第三天会把2楼内容放到3楼,

3楼是历史题目,亲们也可以同样练习,

并且把代码发在下面的一些楼层里,

注明是第几题,楼主会去看代码去验证你的代码准确性和存在的问题

楼主是大水笔,亲们别怕出错,勇敢的训练起来~~

喵~~~!25~

希望版主们的支持~~

米娜桑,一叩首!054~

该贴已经同步到 繁尘、离梦的微博

繁尘、离梦
本帖最后由
展开Biu

本帖最后由 繁尘、离梦 于 2013-4-25 16:55 编辑

这是高阶的亲做的题,如果对2楼不感冒,请往这里来:!!!

[fold]

Fire Net


Suppose that we have a square city with straight streets. A map of a city is a square board with n rows and n columns, each representing a street or a piece of wall.
A blockhouse is a small castle that has four openings through which to shoot. The four openings are facing North, East, South, and West, respectively. There will be one machine gun shooting through each opening.
Here we assume that a bullet is so powerful that it can run across any distance and destroy a blockhouse on its way. On the other hand, a wall is so strongly built that can stop the bullets.
The goal is to place as many blockhouses in a city as possible so that no two can destroy each other. A configuration of blockhouses is legal provided that no two blockhouses are on the same horizontal row or vertical column in a map unless there is at least one wall separating them. In this problem we will consider small square cities (at most 4x4) that contain walls through which bullets cannot run through.
The following image shows five pictures of the same board. The first picture is the empty board, the second and third pictures show legal configurations, and the fourth and fifth pictures show illegal configurations. For this board, the maximum number of blockhouses in a legal configuration is 5; the second picture shows one way to do it, but there are several other ways.

Your task is to write a program that, given a description of a map, calculates the maximum number of blockhouses that can be placed in the city in a legal configuration.
The input file contains one or more map descriptions, followed by a line containing the number 0 that signals the end of the file. Each map description begins with a line containing a positive integer n that is the size of the city; n will be at most 4. The next n lines each describe one row of the map, with a '.' indicating an open space and an uppercase 'X' indicating a wall. There are no spaces in the input file.
For each test case, output one line containing the maximum number of blockhouses that can be placed in the city in a legal configuration.
Sample input:(输入的X是墙 “.”是空白格子,数字是指NxN个正方形方格)
4

.X..

....

XX..

....

2

XX

.X

3.X.

X.X

.X.

3

...

.XX

.XX

4

....

....

....

....

0

Sample output:(你需要输出的是最多可以放多少把机枪,并且使得机枪机枪间不会相互扫到对方)
5

1

5

2

4

看不懂英文没有关系,楼主来解释了:

圆圈是机枪,黑色方块是墙,机枪是没法扫射过去的,机枪可以穿透白色的空格,机枪能上下左右扫射,请问地图上最多可以放几把机枪,并且使得机枪不会打到其他机枪

[/fold]
[fold]

起点位置无视马。

[/fold]

历史题目请戳开看

新题来了!

简单背包问题

foodszhu 第一个解出

[fold]

Description

设有一个背包可以放入的物品重量为S,现有n件物品,重量分别是w1,w2,w3,…wn。

问能否从这n件物品中选择若干件放入背包中,使得放入的重量之和正好为S。

如果有满足条件的选择,则此背包有解,否则此背包问题无解。

Input输入数据有多行,包括放入的物品重量为s,物品的件数n,以及每件物品的重量(输入数据均为正整数)

多组测试数据。

Output对于每个测试实例,若满足条件则输出“YES”,若不满足则输出“NO“

Sample Input

20 5

1 3 5 7 9

Sample Output

YES

[/fold]

004偷来的题

楼主是一个坑爹的人,他看到别人的题目就激动想去偷。但是怕被版主发现,所有他只能分次去偷题目。版主特别喜欢打瞌睡,趁他打瞌睡的时候楼主会去别人那偷题,

但楼主每次直出动一次偷的道数跟版主瞌睡的长短有关,楼主在版主那里装了摄像机能观察版主行动方向,一旦醒来楼主就停止偷盗,等版主巡逻完了瞌睡后继续出动。

版主一天一共打瞌睡N次,也就是楼主可以出动偷N次,楼主的怪癖就是一次偷一道,保证版主这货发现不了。

因为版主瞌睡楼主每天可以偷N次题目(当然楼主有可能去了突然不想偷了)。问题是楼主没人发糖穷至今还在穷到用软盘拷题目,软盘的大小又很小,只有M大小,往往不够用。

加上楼主贪婪的性格,喜欢满载而归,也就是尽可能多占些容量。直到再也装不下了。

Input

输入一个T,表示有T组数据。

每组数据第一行是2个整数N,M(1<= N <=30,1 <= M <=10000000 ) ,第二行包含n个整数,第i个整数表示i题题目占的空间(1到M之间)。

Output

输出最多能花掉楼主软盘多少空间。当然如果你超过了上限,软盘可是会报错的!

Sample Input

1 //这个是一共几组数据

3 10 //前面的3是楼主有3次偷题的机会,后面的是楼主的软盘大小

8 4 5 //这些是题目的大小

Sample Output

9 //最后贪婪的楼主选了4+5这两题,舍弃了8这题。

楼主太聪明了。你肯定没楼主聪明,求破~~@78#

下面一系列的题目都将是背包问题,只是各种各样的,掌握一种可是不够的哦~~~刚把得,米娜桑!#7181!

[查看全文]
繁尘、离梦
本帖最后由
展开Biu

本帖最后由 繁尘、离梦 于 2013-4-25 09:25 编辑

这里是2楼,编辑中……

今天题目就是你了,题目君

[fold]

001鸡兔同笼

Description(这里是介绍)

鸡和兔关在一个笼子里,鸡有2只脚,兔有4只脚,没有例外。已知现在可以看到笼子里m个头和n只脚,求鸡和兔子各有多少只?

Input(这个是输入的意思)

输入两个整数m和n,分别代表笼子里头的个数和脚的个数。(假设m和n都在合法的数据范围内)

Output(这个是输出的意思)

依次输出鸡和兔的只数。(数字为0的也要输出)

Sample Input(示例输入)12 40

Sample Output(示例输出)4 8

[/fold]

接下来,一口首,来吧,来到复杂点的加法题

[fold]

题目大意:非常简单,计算两个小于一千位数的整数的和,要求输入A,B后,输出结果

002 A + B Problem II

Problem Description
I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.

Input
The first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line consists of two positive integers, A and B. Notice that the integers are very large, that means you should not process them by using 32-bit integer. You may assume the length of each integer will not exceed 1000.

Output
For each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line is the an equation "A + B = Sum", Sum means the result of A + B. Note there are some spaces int the equation. Output a blank line between two test cases.

Sample Input(第一个数字是一共有几组数据要计算,2代表要又两组要计算)
2

1 2

112233445566778899 998877665544332211

Sample Output
Case 1:1 + 2 = 3

Case 2:112233445566778899 + 998877665544332211 = 1111111111111111110

[/fold]

003新Joseph问题

原始的Joseph问题的描述如下:有n个人围坐在一个圆桌周围,把这n个人依次编号为1,….,n.。从编号是1的人开始报数,数到第m个人出列,然后从出列的下一个人从新开始报数,数到第m个人又出列,……,如此反复直到所有的人全部出列为止。比如当n=6,m=5的时候,出列的顺序依次是5,4,6,2,3,1。 现在的问题是:假设有k个好人和k个坏人。好人的编号是1到k,坏人的编号是k+1到2k。我们希望求出m的最小值,使得最先出列的k个人都是坏人。Input仅有的一个数字是k( 0 < k < 14 )。Output使得最先出列的k个人都是坏人的m的最小值。

Sample Input

4

Sample Output

30

[查看全文]