本帖最后由 繁尘、离梦 于 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
....
....
....
....
0Sample 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这题。
楼主太聪明了。你肯定没楼主聪明,求破~~
下面一系列的题目都将是背包问题,只是各种各样的,掌握一种可是不够的哦~~~刚把得,米娜桑! |