当前位置:网站首页>CCF elimination games (Full Score code + problem solving ideas + skill summary) February 2, 2015
CCF elimination games (Full Score code + problem solving ideas + skill summary) February 2, 2015
2022-06-30 14:41:00 【A cute little monkey】
Skill summary
Sometimes thinking about a problem , want Think more from a computer perspective
Perhaps the point by point judgment process looks very ” stupid “, But normal thinking ” First judge whether the whole string should be eliminated , Then eliminate “ The code implementation of is more cumbersome
Title Description

Their thinking
- The data range of this question is not large , You can use pure simulated violence to solve problems
- To judge whether this series should be eliminated, we can think about whether the current point should be eliminated
- Move the pointer up, down, left and right from this point , When the values are equal , The pointer moves , Judge whether three or more are equal by pointer spacing
Code implementation
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 35;
int n, m;
int a[N][N];
bool b[N][N];
int main()
{
cin >> n >> m;
for (int i = 0; i < n; i ++)
{
for (int j = 0; j < m; j ++)
{
cin >> a[i][j];
}
}
// Traverse every point , Determine whether it will be eliminated
for (int i = 0; i < n; i ++)
{
for (int j = 0; j < m; j ++)
{
int z = j, y = j, s = i, x = i; // Set up four pointers
while (z >= 0 && a[i][z] == a[i][j]) z --; // At the end of the cycle , The pointer points to the first position that does not meet the condition
while (y < m && a[i][y] == a[i][j]) y ++;
while (s >= 0 && a[s][j] == a[i][j]) s --;
while (x < n && a[x][j] == a[i][j]) x ++;
if (y - z >= 4 || x - s >= 4) b[i][j] = true; // for example 3,4,5 These three spaces are exactly the same color , Then the current pointer z = 2, y = 6, So it should be >= 4
// When there are three or more consecutive identical ones on the left, right, up and down , Then the point will be eliminated
}
}
for (int i = 0; i < n; i ++)
{
for (int j = 0; j < m; j ++)
{
if (!b[i][j]) cout << a[i][j] << " ";
else cout << 0 << " ";
}
cout << endl;
}
return 0;
}
边栏推荐
- ES6 notes
- MySQL back to table query optimization
- Greedy interval problem (5)
- 2021-08-05 leetcode notes
- After the MySQL service on the local computer is started and stopped, some services will automatically stop when they are not used by other services or programs
- Sorting by character frequency
- Wechat applet realizes map navigation + door-to-door recycling
- PHP excel export function encapsulation (based on phpexcel class)
- Laravel RBAC laravel permission use
- Detailed explanation of settimeout() and setinterval()
猜你喜欢

Component communication mode

go channel && select

How does hbuilder display in columns?

Introduction to the construction and development of composer private warehouse

August 24, 2021 deque queue and stack

Summary of use of laravel DCAT admin

Race of golang

Detailed explanation of settimeout() and setinterval()

CCF adjacent number pairs (Full Score code + problem solving ideas + skill summary) 201409-1

Att & CK red team evaluation field (I)
随机推荐
August 24, 2021 deque queue and stack
Use PHP to delete the specified text content in the file
PHP multidimensional array sorting
CCF drawing (full mark code + problem solving ideas + skill summary) February 2, 2014
Att & CK red team evaluation field (I)
数据恢复软件EasyRecovery15下载
How does hbuilder display in columns?
2021-08-07 native and package types
[extensive reading of papers] multimodal joint attribute prediction and value extraction for e-commerce product
Laravel upload error
Binary rotation array (1)
Location of dichotomy
PS dynamic drawing
JS time conversion standard format, timestamp conversion standard format
2021-07-15Caused by: org. quartz. ObjectAlreadyExistsException: Unable to store Job : ‘DEFAULT. TASK_ 1‘
[extensive reading of papers] sentimental analysis of online reviews with a hierarchical attention network
Double pointer letter matching
Computer screenshot how to cut the mouse in
2021 geek challenge Web
JS to realize simple lottery function