标签:结果 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 Resistance. But now he is stuck at the 99-th level. He doesn‘t know what to do and hopes for your help.
Resistanceis a tower defense game. The map used in this game is an n×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 k 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 r1?. Under normal circumstances, it selects the nearest target within the range and fire, causing d1? 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 t1? frames of time for reloading ammunition, so it would not be used again until the (x+t1?)-th frame if it fired at the x-th frame.
A bunker is armed with a flame thrower, whose effective range is up to r2?. 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 d2? 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 d3? damage points.The fire will be quenched at the end of the (x+t2?)-th frame if was hit by a bunker at the x-th frame. Moreover, if a burning invader was hit by a bunker again, supposing that it was hit at the y-th frame, its burning time will be prolonged to the end of the (y+t2?)-th frame.
Now the round starts. There will be E invaders in total, the i-th of which will land at the starting point in the beginning of the i-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 HP1?.
A captain is much more powerful whose initial health point is HP2?, with some level def of defense capability. Once attacked by a defense tower whose damage point is damage, he will suffer from max{1,damage−def} 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.
Sheep has got some details about coming invaders, and he asks you to write a programme to simulate the game for the first T frames of time.
The test data contains several test cases and the first line in input contains an integer Tcase (Tcase≤10) representing the number of test cases.
For every test case, The first line contains five integers n,k,L,E and T 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≤T in all cases.
The following L lines describe the path. The i-th of them contains two integers xi? and yi? describing the coordinate of the i-th cell in the path. We guarantee that any two adjacent cells in the path share a common edge. The first cell locating at (x1?,y1?) is the starting point and the last cell locating at (xL?,yL?) is the destination where the village is.
The next line contains seven integers r1?,d1?,t1?,r2?,d2?,t2? and d3? indicating all parameters about defense towers described as above. And then a line containing three integers HP1?,HP2? and def describes parameters about invaders.
The next k lines describe all defense towers. The i-th of them contains three integers typei?,xi? and yi? where (xi?,yi?) is the coordinate of the i-th defense tower, and if typei?=1 the tower is a gun tower, or a bunker if typei?=2.
The last line contains a string of length E, the i-th digit in which describes the type of the i-th invader where we use the character 1 to represent a private, and 2 to represent a captain.
All numbers in the input are positive integers and no more than 400.
标签:结果 some begin noi test neither des end 前言
原文地址:https://www.cnblogs.com/jinkun113/p/12764768.html