当前位置:网站首页>7-11 mechanic mustadio (PTA program design)
7-11 mechanic mustadio (PTA program design)
2022-07-06 13:56:00 【Programming Lindaiyu】
stay MMORPG《 Final fantasy 14》 Copy of “ A place of pleasure, oubona monastery ” in ,BOSS Mechanic mstadio will accept the player's challenge .
You need to process this copy, one of the mechanisms :N×M The size of the map is split into N×M individual 1×1 Lattice of ,BOSS Will select several rows or / And several columns of release skills , Players cannot stand on a square that releases skills , Otherwise you will be hit and fail .
Given BOSS All row or column information for releasing skills , Please calculate how many grids are safe in the end .
Input format :
The first line of input is three integers N,M,Q (1≤N×M≤105,0≤Q≤1000), Indicates that the map is N That's ok M Column size and selected rows / Number of columns .
Next Q That's ok , Two numbers per line Ti,Ci, among Ti=0 Express BOSS A whole row is selected ,Ti=1 Indicates that an entire column is selected ,Ci Select the line number for / Column number . The numbers of rows and columns are from 1 Start .
Output format :
Output a number , Indicates the number of safety grids .
sample input :
5 5 3
0 2
0 4
1 3
sample output :
12
Code (Python):
n,m,q=map(int,input().split()) # The first line of input is three integers N,M,Q , Indicates that the map is N That's ok M Column size and selected rows / Number of columns .
list1=[] # Store map
list2=[] # The number of rows or columns storing the data to be deleted , That is, input the number in the sample except the first line
for i in range(n): # Initialize the 2D list , That is, build a map , Make its values all 1
h=[] # This is actually equivalent to list1 There is n Elements , Each element has m Elements , Composition n*m The map of
for j in range(m):
h.append(1)
list1.append(h)
for i in range(q): # Input of two-dimensional array , I will store the number in the input sample in the form of a two-dimensional list except the first line
s=input()
list2.append([int(n) for n in s.split()]) # Notice the square brackets inside
for i in range(q): # To delete
x=list2[i][1]-1 # See which row or column you want to delete , Because the rows or columns in the question are from 1 At the beginning , And in the list is from 0 At the beginning , So we need to reduce 1
if list2[i][0]==0: # Delete a whole line
for j in range(m): # When deleting rows, see how many columns ,m Column
list1[x][j]=0 # Use to place 0 Said to delete
if list2[i][0]==1: # Delete an entire column
for j in range(n): # See how many rows there are when deleting columns ,n That's ok
list1[j][x]=0 # Use to place 0 Said to delete
count=0 # Number of safety grids
for i in range(n): # Traverse the map , Look, how many are there 1, That is, there are several safety grids
for j in range(m):
if list1[i][j]==1:
count+=1
print(count) # Output the number of safety grids
When I first saw this problem, I thought it was very difficult , Because it looks complicated . But I still tried it , It's not difficult to find , Is the most basic mathematical knowledge , There is no hard Algorithm . therefore , When you come across a seemingly difficult problem , And don't give up , Try to do it , To analyze , Maybe it's not very difficult , Or maybe it's really a little difficult , But how do you know if you will not try , What if you make it yourself ? So don't set limits on yourself , Try boldly , To challenge .
The above program gives more detailed comments , For novice Xiaobai's reference . The idea of program design or code implementation is not optimal , You are welcome to correct your mistakes or give better ideas .
I am a rookie who wants to be Kunpeng , Everyone's encouragement is my driving force , Welcome to like collection comments !
边栏推荐
- .Xmind文件如何上传金山文档共享在线编辑?
- HackMyvm靶机系列(7)-Tron
- 力扣152题乘数最大子数组
- Difference and understanding between detected and non detected anomalies
- 甲、乙机之间采用方式 1 双向串行通信,具体要求如下: (1)甲机的 k1 按键可通过串行口控制乙机的 LEDI 点亮、LED2 灭,甲机的 k2 按键控制 乙机的 LED1
- The difference between abstract classes and interfaces
- 使用Spacedesk实现局域网内任意设备作为电脑拓展屏
- SRC mining ideas and methods
- Mixlab unbounded community white paper officially released
- Renforcer les dossiers de base de l'apprentissage
猜你喜欢
7-7 7003 组合锁(PTA程序设计)
7-5 走楼梯升级版(PTA程序设计)
撲克牌遊戲程序——人機對抗
记一次猫舍由外到内的渗透撞库操作提取-flag
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
强化学习基础记录
Strengthen basic learning records
MySQL锁总结(全面简洁 + 图文详解)
Callback function ----------- callback
强化学习基础记录
随机推荐
力扣152题乘数最大子数组
实验九 输入输出流(节选)
The difference between overloading and rewriting
7-7 7003 组合锁(PTA程序设计)
7-3 construction hash table (PTA program design)
Implementation principle of automatic capacity expansion mechanism of ArrayList
Experiment 4 array
(original) make an electronic clock with LCD1602 display to display the current time on the LCD. The display format is "hour: minute: Second: second". There are four function keys K1 ~ K4, and the fun
Detailed explanation of redis' distributed lock principle
MySQL lock summary (comprehensive and concise + graphic explanation)
简单理解ES6的Promise
Leetcode.3 无重复字符的最长子串——超过100%的解法
实验六 继承和多态
优先队列PriorityQueue (大根堆/小根堆/TopK问题)
HackMyvm靶机系列(6)-videoclub
[the Nine Yang Manual] 2019 Fudan University Applied Statistics real problem + analysis
7-1 output all primes between 2 and n (PTA programming)
Matlab opens M file garbled solution
canvas基础2 - arc - 画弧线
[the Nine Yang Manual] 2020 Fudan University Applied Statistics real problem + analysis