7213:垃圾炸弹

题目链接:http://noi.openjudge.cn/ch0201/7213/

总时间限制: 1000ms 内存限制: 65536kB
描述

    2014年巴西世界杯(2014 FIFA World Cup)开踢啦!为了方便球迷观看比赛,里约街道上很多路口都放置了的直播大屏幕,但是人群散去后总会在这些路口留下一堆垃圾。为此巴西政府决定动用一种最新发明——“垃圾炸弹”。这种“炸弹”利用最先进的量子物理技术,爆炸后产生的冲击波可以完全清除波及范围内的所有垃圾,并且不会产生任何其他不良影响。炸弹爆炸后冲击波是以正方形方式扩散的,炸弹威力(扩散距离)以d给出,表示可以传播d条街道。

    例如下图是一个d=1的“垃圾炸弹”爆炸后的波及范围。

假设里约热内卢市的布局为严格的1025*1025的网格状,由于财政问题市政府只买得起一枚“垃圾炸弹”,希望你帮他们找到合适的投放地点,使得一次清除的垃圾总量最多(假设垃圾数量可以用一个非负整数表示,并且除设置大屏幕的路口以外的地点没有垃圾)。

输入第一行给出“炸弹”威力d(1 <= d <= 50)。第二行给出一个数组n(1 <= n <= 20)表示设置了大屏幕(有垃圾)的路口数目。接下来n行每行给出三个数字x, y, i, 分别代表路口的坐标(x, y)以及垃圾数量i. 点坐标(x, y)保证是有效的(区间在0到1024之间),同一坐标只会给出一次。输出输出能清理垃圾最多的投放点数目,以及能够清除的垃圾总量。样例输入

1
2
4 4 10
6 6 20

样例输出

1 30

算法分析:

这个题目可以考虑利用二维数组累加和计算子矩阵的方法求解。下面的代码思路比较新颖,特地记载。

来源:http://blog.csdn.net/wyi06/article/details/59055522

思路:枚举所有点(i,j),对每一个点,假设在该点安放炸弹,然后扫描所有大屏幕的坐标,统计有多少个大屏幕的坐标在该炸弹的波及范围内。

因为大屏幕数量比较少,这个处理方式也是比较合理的。

 1 #include <stdio.h>  
 2 #include <string.h>  
 3   
 4   
 5 struct Node  
 6 {  
 7     int x, y, garbageCount;  
 8 } a[21];  
 9   
10 int main()   
11 {  
12   
13         int d, n;  
14         scanf("%d", &d);  
15         scanf("%d", &n);  
16         for (int i = 0; i < n; i++)   
17         {  
18             scanf("%d%d%d", &a[i].x, &a[i].y, &a[i].garbageCount);  
19               
20         }  
21         int maxSum = 0, maxSumCount = 0;  
22    
23   
24         for (int r = 0; r < 1025; r++)   
25         {  
26             for (int c = 0; c < 1025; c++)   
27             {  
28                 int sum = 0;  
29                 for (int i = 0; i < n; i++)   
30                 {  
31                     if (a[i].x >= r - d && a[i].x <= r + d && a[i].y >= c - d && a[i].y <= c + d)   
32                     {  
33                         sum += a[i].garbageCount;  
34                     }  
35                 }  
36                 if (sum > maxSum)   
37                 {  
38                     maxSum = sum;  
39                     maxSumCount = 1;  
40                 }  
41                 else if (sum == maxSum)  
42                 {  
43                     maxSumCount++;  
44                 }  
45             }  
46         }  
47         printf("%d %d\n", maxSumCount, maxSum);  
48   
49 }  

 

当然可以!下面是一个使用Cocos Creator和TypeScript创建炸弹人游戏的示例代码: ``` const { ccclass, property } = cc._decorator; enum ItemType { BombRange, SpeedUp } @ccclass export default class BombMan extends cc.Component { @property(cc.Prefab) private playerPrefab: cc.Prefab = null; @property(cc.Prefab) private enemyPrefab: cc.Prefab = null; @property(cc.Prefab) private itemPrefab: cc.Prefab[] = []; @property(cc.SpriteFrame) private brickSprite: cc.SpriteFrame = null; private player: cc.Node = null; private enemies: cc.Node[] = []; private items: cc.Node[] = []; private map: number[][] = []; private gridSize: number = 45; private gridRows: number = 15; private gridCols: number = 15; private bombRange: number = 1; private playerSpeed: number = 200; onLoad() { this.generateMap(); this.spawnPlayer(); this.scheduleOnce(this.spawnEnemy, Math.random() * 3 + 2); this.scheduleOnce(this.spawnItem, Math.random() * 5 + 3); } generateMap() { for (let i = 0; i < this.gridRows; i++) { this.map[i] = []; for (let j = 0; j < this.gridCols; j++) { let tileType = Math.random() < 0.8 ? 0 : 1; this.map[i][j] = tileType; if (tileType === 1) { let brickNode = new cc.Node(); let sprite = brickNode.addComponent(cc.Sprite); sprite.spriteFrame = this.brickSprite; brickNode.parent = this.node; brickNode.setPosition(j * this.gridSize, i * this.gridSize); } } } } spawnPlayer() { this.player = cc.instantiate(this.playerPrefab); this.player.parent = this.node; this.player.setPosition(this.gridSize / 2, this.gridSize / 2); } spawnEnemy() { let enemyNode = cc.instantiate(this.enemyPrefab); enemyNode.parent = this.node; // 随机生成敌人的位置 let randomRow = Math.floor(Math.random() * this.gridRows); let randomCol = Math.floor(Math.random() * this.gridCols); enemyNode.setPosition(randomCol * this.gridSize, randomRow * this.gridSize); this.enemies.push(enemyNode); // 随机生成敌人的生成时间间隔 this.scheduleOnce(this.spawnEnemy, Math.random() * 3 + 2); } spawnItem() { let itemType = Math.floor(Math.random() * this.itemPrefab.length); let itemNode = cc.instantiate(this.itemPrefab[itemType]); itemNode.parent = this.node; // 随机生成道具的位置 let randomRow = Math.floor(Math.random() * this.gridRows); let randomCol = Math.floor(Math.random() * this.gridCols); itemNode.setPosition(randomCol * this.gridSize, randomRow * this.gridSize); this.items.push(itemNode); // 随机生成道具的生成时间间隔 this.scheduleOnce(this.spawnItem, Math.random() * 5 + 3); } // ... } ``` 这只是一个简单的示例代码,包含了地图的生成、玩家、敌人和道具的生成。你可以根据自己的需求进一步完善游戏逻辑和其他功能。希望对你有所帮助!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值