码迷,mamicode.com
首页 > 其他好文 > 详细

[知识点] 2.1 枚举与模拟

时间:2020-04-24 00:46:17      阅读:74      评论:0      收藏:0      [点我收藏+]

标签:结果   some   begin   noi   test   neither   des   end   前言   

前言

这篇文章是在不知道该写些什么,但是作为算法里最基本的东西,还是得给点排面哈。

 

子目录列表

2.1 枚举与模拟

1、枚举算法

枚举是基于现有知识来猜测答案的一种问题求解策略。

 

2、模拟算法

模拟是指通过计算机来模拟题目要求的操作。它是最简单的一类题型,但如果它真的出现在竞赛中了,也往往是最恶心的题,比如:

 

 

看题面就知道是一道很爽的题呢(而且这个题面应该不算很长的?

这道来自 NOIP 的题基本也可以总结出在竞赛中出现的模拟题的特点:

细节多,操作繁杂,代码量大。

它一般不需要储备什么算法知识,也不需要用到数据结构,所以在思维上就要弱其他题型一等,所以出题人往往会在其他方面加大马力,比如增加大量的操作步骤,或者套入一个引人入胜的故事来让你沉迷情节无法自拔增加对题目关键部分的提炼难度。从亲身体会上来看,考场/赛场上做模拟题做难的地方并非编程,而是调试——因为代码量大,且大多是各种分支循环结构的嵌套,一旦花了大功夫写完整个程序长舒一口气再代入样例发现答案不对的时候心里就要咯噔一下;然后又花大功夫终于发现代码里一个 i 写成了 j 马上改了然后样例对了长舒一口气再提交一发结果一个红红的 WA 映入眼帘的时候更是心态崩溃,而如此往复若干次却死都找不到问题所在就会进入一个心态爆炸和找不到问题的恶性循环(为什么我要吐槽这么多?)

下面给出一些关于做大型模拟题的建议:

1、切忌直接开始码代码。认真读题,理清主干,先画出大概的流程图;

2、根据流程图的主干和分支,尽量将代码切割成若干子问题,操作主体多定义成类或结构体,操作过程多定义成子函数,且名称尽量能在一片混乱中能一眼分辨其定义和作用;

3、待补充。

最后给出例题代码:

 

Recently, Sheep gets fascinated in a tower defense game called ResistanceResistance. But now he is stuck at the 9999-th level. He doesn‘t know what to do and hopes for your help.

ResistanceResistanceis a tower defense game. The map used in this game is an n\times nn×n. A specific path consisting of several cells is given in which any two adjacent cells share a common edge. We guarantee that the path never passes by a cell twice. A village is locating at the destination of the path. Some evil invaders will land at the starting point, go along the path and attempt to invade the village.

To secure the village, Sheep has deployed kk defense towers in the map to attack invaders. All defense towers are lying at some locations but neither on the path nor at the starting point or the destination. All defense towers can be divided into two kinds: gun towers and bunkers.

A gun tower is armed with the machine gun, whose effective range is up to r_1r1?. Under normal circumstances, it selects the nearest target within the range and fire, causing d_1d1? damage points for its target. If there are more than one nearest enemies (with the same smallest Euclidean distance), the one who can reach the village with least steps on the path. The rules of the game guarantee that there wouldn‘t be more ambiguities. After an attack, the machine gun will need t_1t1? frames of time for reloading ammunition, so it would not be used again until the (x+t_1)(x+t1?)-th frame if it fired at the xx-th frame.

A bunker is armed with a flame thrower, whose effective range is up to r_2r2?. It can fire at every time without any restrictions like gun towers. It also selects a target satisfying the similar conditions as above. An attack will cause d_2d2? damage points for its target, and the attacked invader will start to burn in the next frame of time. At each frame when the invader is burning, it suffers from d_3d3? damage points.The fire will be quenched at the end of the (x+t_2)(x+t2?)-th frame if was hit by a bunker at the xx-th frame. Moreover, if a burning invader was hit by a bunker again, supposing that it was hit at the yy-th frame, its burning time will be prolonged to the end of the (y+t_2)(y+t2?)-th frame.

Now the round starts. There will be EE invaders in total, the ii-th of which will land at the starting point in the beginning of the ii-th frame of time. After that, any invader will take a step forward along the path in each frame of time. All invaders can be also divided into two kinds: privates and captains.

A private is the most inferior warrior with no special ability whose initial health point is HP_1HP1?.

A captain is much more powerful whose initial health point is HP_2HP2?, with some level defdef of defense capability. Once attacked by a defense tower whose damage point is damagedamage, he will suffer from \max\{1,damage-def\}max{1,damagedef} damage point. Note that attacks from different defense towers in any frame should be considered separately, but the damage caused by burning will not be considered as an attack within the defense capability.

An invader with health point less than zero is presumed dead and will be removed.

Let‘s make a summary of what will happen in a frame of time in this game.

  • The Enemy Step. All alive invaders take a step forward along the path. Then, a new invader may land at the starting point.
  • The Fire Step. All defense towers select their target. Then they fire together while those defense towers which have to target or wait for reloading ammunitions do nothing.
  • The Damage Estimation. Calculate the damage points and deduce the health points of all invaders. The burning damage will also be calculated at this time.
  • The Ending Step. All invaders with negative health points will be removed. If an alive invader is staying at the destination of the path, he invades the village successfully and will also be removed from the game.

Sheep has got some details about coming invaders, and he asks you to write a programme to simulate the game for the first TT frames of time.

Input

The test data contains several test cases and the first line in input contains an integer Tcase~(Tcase\le 10)Tcase (Tcase10) representing the number of test cases.

For every test case, The first line contains five integers n, k, L, En,k,L,E and TT indicating the size of the map, the number of the defense towers, the length of the path, the number of invaders and the number of frames among your simulation. We guarantee that E\le TET in all cases.

The following LL lines describe the path. The ii-th of them contains two integers x_ixi? and y_iyi? describing the coordinate of the ii-th cell in the path. We guarantee that any two adjacent cells in the path share a common edge. The first cell locating at (x_1,y_1)(x1?,y1?) is the starting point and the last cell locating at (x_L,y_L)(xL?,yL?) is the destination where the village is.

The next line contains seven integers r_1, d_1, t_1, r_2, d_2, t_2r1?,d1?,t1?,r2?,d2?,t2? and d_3d3? indicating all parameters about defense towers described as above. And then a line containing three integers HP_1,HP_2HP1?,HP2? and defdef describes parameters about invaders.

The next kk lines describe all defense towers. The ii-th of them contains three integers type_i, x_itypei?,xi? and y_iyi? where (x_i,y_i)(xi?,yi?) is the coordinate of the ii-th defense tower, and if type_i=1typei?=1 the tower is a gun tower, or a bunker if type_i=2typei?=2.

The last line contains a string of length EE, the ii-th digit in which describes the type of the ii-th invader where we use the character 11 to represent a private, and 22 to represent a captain.

All numbers in the input are positive integers and no more than 400400.

[知识点] 2.1 枚举与模拟

标签:结果   some   begin   noi   test   neither   des   end   前言   

原文地址:https://www.cnblogs.com/jinkun113/p/12764768.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!