Blue Bridge Cup countdown to the fifth day of daily review

Hello everyone, I am Bubble. Today I bring you the content of the review. Because of the review, I will pass it by.

content

1. Square sequence

2. Crossing the minefield


1. Square sequence

Topic link: Square Sequence - Lanqiao Cloud Course (lanqiao.cn)

Topic requirements:

Xiao Ming wants to find two positive integers XX and YY, satisfying

  1. 2019<X<Y;
  2. 2019^2, X^2, Y^2 form an arithmetic sequence.

What is the minimum value of X + YX + Y among all possible solutions?

Problem solving ideas:

Violence

#include<bits/stdc++.h>
using namespace std;
int main()
{
    for(int i=2020;i<10001;i++)
    {
        int x = i*i*2-2019*2019;
        int y = sqrt(x);
        if(y*y==x)
        {
            cout<<i+y;
            return 0;
        }
    }
}

2. Crossing the minefield

Topic link: Crossing the minefield - Lanqiao Cloud Course (lanqiao.cn)

Topic requirements:

X-star's tank tank is very strange, it must alternately pass through the positive energy radiation area and the negative energy radiation area to maintain normal operation, otherwise it will be scrapped.

A tank needs to go from area A to area B (areas A and B are safe areas, with no positive or negative energy characteristics), how to get the shortest path?

The known map is a square matrix, on which the A and B areas are marked with letters, and the other areas are marked with positive or negative signs to indicate the positive and negative energy radiation areas, respectively.

E.g:

A + - + -

- + - - +

- + + + -

+ - + - +

B + - + -

Tanks can only move horizontally or vertically to adjacent zones.

Problem solving ideas:

BFS template

#include<bits/stdc++.h>
using namespace std;
const int N = 101;
char s[N][N];
int dx,dy,tx,ty,n;
int ddx[]={1,0,0,-1};
int ddy[]={0,1,-1,0};
int vis[N][N];
struct node{
	int x,y,t;
	char b;
};
int bfs()
{
	vis[dx][dy] = 1;
	queue<node>q;
	q.push({dx,dy,0,'r'});
	while(q.size())
	{
		node z = q.front();
		q.pop();
		if(z.x==tx&&z.y==ty)
		{
			return z.t;
		}
		for(int i=0;i<4;i++)
		{
			int x = z.x+ddx[i];
			int y = z.y+ddy[i];
			if(!vis[x][y]&&x>0&&y>0&&x<=n&&y<=n&&s[x][y]!=z.b)
			{
				q.push({x,y,z.t+1,s[x][y]});
				vis[x][y] = 1;
			}
		}
	}
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			cin>>s[i][j];
			if(s[i][j]=='A')
			{
				dx=i;
				dy=j;
			}
			if(s[i][j]=='B')
			{
				tx=i;
				ty=j;
			}
		}
	}
	cout<<bfs();
	return 0;
}

Guess you like

Origin blog.csdn.net/qq_45400861/article/details/123989068