程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python solves the real problem of ccf-csp 202206-2 - treasure hunt! Adventure!

編輯:Python

Students who want to check the real problems and solutions of other problems can go to check :CCF-CSP True problem with complete solution

 

Question number :202206-2 The title of the test question : Treasure hunt ! Great adventure ! The time limit :500ms Memory limit :512.0MB Problem description :

Background

Summer vacation is coming . Unfortunately for a variety of reasons , Small P The original travel plan was cancelled . Disappointed little P I can only stay on West Island for a slightly monotonous holiday …… until ……

One day , Small P Got a mysterious treasure map .

Problem description

On the island of sisieffer, there are  n  tree , The specific positions of these trees are recorded on a green map .
In short , The greening map of West Aifo island can be regarded as a map with a size of  (L+1)×(L+1)  Of  01  matrix  A,
The lower left corner of the map ( coordinate  (0,0)) And the upper right corner ( coordinate  (L,L)) They correspond to each other  A[0][0]  and  A[L][L].
among  A[i][j]=1  Representation coordinates  (i,j)  There is a tree planted there ,A[i][j]=0  The coordinate  (i,j)  There are no trees .
In other words , matrix  A  There are and only  n  individual  1  It shows the island of West Eiffer  n  The exact location of the tree .

Legend has it that , The great adventurer Dunton's treasure is buried under a tree .
also , Dunton also cut a small piece from the green map of West West iver island , Make a treasure map to indicate its location .
say concretely , The treasure map can be regarded as a treasure map with a size of  (S+1)×(S+1)  Of  01  matrix  B(S  Far less than  L), Corresponding  A  Some part of .
Theoretically , Greening map  A  There is a coordinate in  (x,y)(0≤x,y≤L−S) And the treasure map  B  The lower left corner  (0,0)  Corresponding , The meet :
Yes  B  Any coordinate on  (i,j)(0≤i,j≤S), There are  A[x+i][y+j]=B[i][j].
When the above conditions are met , We think of the treasure map  B  Corresponding to the greening map  A  The lower left corner in the middle is  (x,y)、 The upper right corner is  (x+S,y+S)  Region .

actually , Considering that the treasure map depicts only a small area , Coordinates satisfying the above conditions  (x,y)  There may well be more than one .
Please refer to the greening map of West Eiffer island  n  The location of the tree , And small  P  The treasure map in your hand , Judge how many coordinates in the greening map meet the conditions .

Specially , The lower left corner of the treasure map must be a tree , namely  A[x][y]=B[0][0]=1, It shows where the treasure is buried .

Input format

Reading data from standard input .

The first line of input contains three positive integers separated by spaces  n、L  and  S, They represent the number of trees on the island of West Eiffer 、 The size of green map and treasure map .

Because the size of the greening map is too large , The input data contains only  n  The coordinates of a tree, not a complete map ; And then  n  Each row contains two integers separated by spaces  x  and  y, Represents the coordinates of a tree , Satisfy  0≤x,y≤L  And the same coordinate will not be repeated .

Last  (S+1)  Line input small P The complete treasure map in your hand , Among them the first  i  That's ok (0≤i≤S) Contains space delimited  (S+1)  individual  0  and  1, Express  B[S−i][0]⋯B[S−i][S].
We need to pay attention to , The first input is  B[S][0]⋯B[S][S]  a line ,B[0][0]⋯B[0][S]  Enter... At the end of a line .

Output format

Output to standard output .

Output an integer , Indicates how many coordinates in the green map can correspond to the lower left corner of the treasure map , That is to say, there may be buried treasures .

Examples 1 Input

5 100 2
0 0
1 1
2 2
3 3
4 4
0 0 1
0 1 0
1 0 0

Examples 1 Output

3

Examples 1 explain

On the green map  (0,0)、(1,1)  and  (2,2)  There may be treasures buried in all three places .

Examples 2 Input

5 4 2
0 0
1 1
2 2
3 3
4 4
0 0 0
0 1 0
1 0 0

Examples 2 Output

0

Examples 2 explain

If you compare the lower left corner of the treasure map with the greening map  (3,3)  Corresponding to , The upper right corner of the treasure map will exceed the boundary of the green map , The correspondence is not successful .

The subtasks

40%  The test data meet :L≤50;

70%  The test data meet :L≤2000;

All test data meet :n≤1000、L≤109  And  S≤50.

Tips

The answer is not included in the actual test data  0  The use case .

The real question comes from : Treasure hunt ! Great adventure !

  Interested students can go in and practice

70 Sub topic solution : Memory overrun

n, l, s = map(int,input().split())
points = [[i for i in map(int,input().split())] for j in range(n)]
money = [[i for i in map(int,input().split())] for j in range(s+1)]
data = [[0 for i in range(l+1)] for j in range(l+1)]
for point in points:
x = point[0]
y = point[1]
data[x][y] = 1
length = len(money)
if length%2 == 0:
for i in range(length//2):
for j in range(length):
money[i][j], money[s-i][j] = money[s-i][j], money[i][j]
else:
lake = length//2+1
for i in range(length//2):
if i == lake:
continue
for j in range(length):
money[i][j], money[s-i][j] = money[s-i][j], money[i][j]
time = 0
for point in points:
x = point[0]
y = point[1]
q = 0
for i in range(s+1):
if x+i > l:
q = 1
break
if q == 1:
break
for j in range(s+1):
if y+j > l:
q = 1
break
if money[i][j] == data[x+i][y+j]:
continue
else:
q = 1
break
if q == 0:
time += 1
print(time)

Running results :


ccf-csp Practice column   

https://blog.csdn.net/weixin_53919192/category_11828479.html?spm=1001.2014.3001.5482https://blog.csdn.net/weixin_53919192/category_11828479.html?spm=1001.2014.3001.5482


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved