当前位置:网站首页>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 :
12Code (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 !
边栏推荐
- Strengthen basic learning records
- Mixlab unbounded community white paper officially released
- [graduation season · advanced technology Er] goodbye, my student days
- 1. First knowledge of C language (1)
- 【MySQL-表结构与完整性约束的修改(ALTER)】
- Zatan 0516
- Programme de jeu de cartes - confrontation homme - machine
- 【数据库 三大范式】一看就懂
- 7-15 h0161. Find the greatest common divisor and the least common multiple (PTA program design)
- 仿牛客技术博客项目常见问题及解答(三)
猜你喜欢

Meituan dynamic thread pool practice ideas, open source

Programme de jeu de cartes - confrontation homme - machine

FAQs and answers to the imitation Niuke technology blog project (I)

canvas基础1 - 画直线(通俗易懂)
![[VMware abnormal problems] problem analysis & Solutions](/img/64/f44864da600b61a1a646a5865a2083.jpg)
[VMware abnormal problems] problem analysis & Solutions

This time, thoroughly understand the MySQL index

仿牛客技术博客项目常见问题及解答(二)

3. Input and output functions (printf, scanf, getchar and putchar)

.Xmind文件如何上传金山文档共享在线编辑?
![[dark horse morning post] Shanghai Municipal Bureau of supervision responded that Zhong Xue had a high fever and did not melt; Michael admitted that two batches of pure milk were unqualified; Wechat i](/img/d7/4671b5a74317a8f87ffd36be2b34e1.jpg)
[dark horse morning post] Shanghai Municipal Bureau of supervision responded that Zhong Xue had a high fever and did not melt; Michael admitted that two batches of pure milk were unqualified; Wechat i
随机推荐
Canvas foundation 1 - draw a straight line (easy to understand)
Matlab opens M file garbled solution
这次,彻底搞清楚MySQL索引
[au cours de l'entrevue] - Comment expliquer le mécanisme de transmission fiable de TCP
Miscellaneous talk on May 27
Renforcer les dossiers de base de l'apprentissage
TypeScript快速入门
5月27日杂谈
[面试时]——我如何讲清楚TCP实现可靠传输的机制
渗透测试学习与实战阶段分析
Read only error handling
【头歌educoder数据表中数据的插入、修改和删除】
Zatan 0516
2022 Teddy cup data mining challenge question C idea and post game summary
Detailed explanation of redis' distributed lock principle
HackMyvm靶机系列(6)-videoclub
仿牛客技术博客项目常见问题及解答(二)
Force deduction 152 question multiplier maximum subarray
[MySQL table structure and integrity constraint modification (Alter)]
7-3 构造散列表(PTA程序设计)