当前位置:网站首页>7-11 机工士姆斯塔迪奥(PTA程序设计)
7-11 机工士姆斯塔迪奥(PTA程序设计)
2022-07-06 09:22:00 【编程林黛玉】
在 MMORPG《最终幻想14》的副本“乐欲之所瓯博讷修道院”里,BOSS 机工士姆斯塔迪奥将会接受玩家的挑战。
你需要处理这个副本其中的一个机制:N×M 大小的地图被拆分为了 N×M 个 1×1 的格子,BOSS 会选择若干行或/及若干列释放技能,玩家不能站在释放技能的方格上,否则就会被击中而失败。
给定 BOSS 所有释放技能的行或列信息,请你计算出最后有多少个格子是安全的。
输入格式:
输入第一行是三个整数 N,M,Q (1≤N×M≤105,0≤Q≤1000),表示地图为 N 行 M 列大小以及选择的行/列数量。
接下来 Q 行,每行两个数 Ti,Ci,其中 Ti=0 表示 BOSS 选择的是一整行,Ti=1 表示选择的是一整列,Ci 为选择的行号/列号。行和列的编号均从 1 开始。
输出格式:
输出一个数,表示安全格子的数量。
输入样例:
5 5 3
0 2
0 4
1 3
输出样例:
12
代码(Python):
n,m,q=map(int,input().split()) #输入第一行是三个整数 N,M,Q ,表示地图为 N 行 M 列大小以及选择的行/列数量。
list1=[] #存放地图
list2=[] #存放要删除的数据的行或列数,即输入样例中除第一行以外的数
for i in range(n): #初始化二维列表,即构建地图,使其值全部为1
h=[] #这里其实相当于list1中有n个元素,每个元素里又有m个元素,即构成n*m的地图
for j in range(m):
h.append(1)
list1.append(h)
for i in range(q): #二维数组的输入,即将输入样例中除第一行以外的数以二维列表的形式存储
s=input()
list2.append([int(n) for n in s.split()]) #注意里面是方括号
for i in range(q): #开始删除
x=list2[i][1]-1 #看要删除哪一行或列,因为题中的行或列都是从1开始的,而列表中的是从0开始的,所以要减1
if list2[i][0]==0: #删除一整行
for j in range(m): #删除行的时候看有几列,m列
list1[x][j]=0 #用置0表示删除
if list2[i][0]==1: #删除一整列
for j in range(n): #删除列的时候看有几行,n行
list1[j][x]=0 #用置0表示删除
count=0 #安全格子的数量
for i in range(n): #遍历地图,看有几个1,即有几个安全格子
for j in range(m):
if list1[i][j]==1:
count+=1
print(count) #输出安全格子的数量
我在一开始看到这道题的时候以为它很难,因为看上去很复杂。但还是上手尝试了一下,发现一点也不难,就是最基础的数学知识,也没有很难的算法。所以,当大家遇到一道看上去很难的题的时候,也不要放弃,要尝试入手去做,去分析,说不定它没有很难,又或许它确实有点难度,可是不尝试怎么知道自己会不会呢,万一自己做出来了呢?所以不要给自己设限,要大胆额去尝试,去挑战。
上面的程序给出了比较详细的注释,以便新手小白参考。程序的思路设计或者代码实现并不是最优的,欢迎各位大佬指正错误或者给出更优质的思路。
我是一只想成为鲲鹏的菜鸟,大家的鼓励是我前进的动力,欢迎大家点赞收藏评论哦!
边栏推荐
- C语言实现扫雷游戏(完整版)
- 7.数组、指针和数组的关系
- Principles, advantages and disadvantages of two persistence mechanisms RDB and AOF of redis
- 2022泰迪杯数据挖掘挑战赛C题思路及赛后总结
- Implement queue with stack
- ABA问题遇到过吗,详细说以下,如何避免ABA问题
- 记一次猫舍由外到内的渗透撞库操作提取-flag
- 使用Spacedesk实现局域网内任意设备作为电脑拓展屏
- Leetcode. 3. Longest substring without repeated characters - more than 100% solution
- Mode 1 two-way serial communication is adopted between machine a and machine B, and the specific requirements are as follows: (1) the K1 key of machine a can control the ledi of machine B to turn on a
猜你喜欢
3. Number guessing game
Leetcode. 3. Longest substring without repeated characters - more than 100% solution
3. C language uses algebraic cofactor to calculate determinant
Change vs theme and set background picture
(super detailed II) detailed visualization of onenet data, how to plot with intercepted data flow
强化学习系列(一):基本原理和概念
Service ability of Hongmeng harmonyos learning notes to realize cross end communication
The latest tank battle 2022 full development notes-1
使用Spacedesk实现局域网内任意设备作为电脑拓展屏
(ultra detailed onenet TCP protocol access) arduino+esp8266-01s access to the Internet of things platform, upload real-time data collection /tcp transparent transmission (and how to obtain and write L
随机推荐
Miscellaneous talk on May 27
Implementation of count (*) in MySQL
2. First knowledge of C language (2)
MySQL事务及实现原理全面总结,再也不用担心面试
Zatan 0516
Relationship between hashcode() and equals()
Redis实现分布式锁原理详解
[graduation season · advanced technology Er] goodbye, my student days
View UI plus releases version 1.1.0, supports SSR, supports nuxt, and adds TS declaration files
【九阳神功】2021复旦大学应用统计真题+解析
甲、乙机之间采用方式 1 双向串行通信,具体要求如下: (1)甲机的 k1 按键可通过串行口控制乙机的 LEDI 点亮、LED2 灭,甲机的 k2 按键控制 乙机的 LED1
Using spacedesk to realize any device in the LAN as a computer expansion screen
Implementation principle of automatic capacity expansion mechanism of ArrayList
vector
Floating point comparison, CMP, tabulation ideas
为什么要使用Redis
The latest tank battle 2022 full development notes-1
Reinforcement learning series (I): basic principles and concepts
3.猜数字游戏
6.函数的递归