Blue Bridge Cup Daily Question 2023.9.29

Lanqiao Cup Competition Past Questions - C&C++ University Group B - Lanqiao Cloud Class (lanqiao.cn)

Title description 1

Question analysis

Seeing that there are 32 bits, we use this as a starting point,

B represents byte 1B = 8b

b represents bit, 32 bits is 4 bytes (B)

1KB = 1024B

1MB = 1024KB

(256 * 1024 * 1024) / 4 = 67108864

So the answer is 67108864

Title description 2

Question analysis

Just treat each array from 0 to 9 as a type of card, and you can subtract this if the number you loop through needs it. If it decreases to less than 0, just output this +1 (answer 3181)

#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int f[N], flag;
int main()
{
	for(int i = 0; i <= 9; i ++)
	{
		f[i] = 2021;
	}
	for(int i = 1; ; i ++)
	{
		int x = i; 
		while(x)
		{
			int y = x % 10;
			x /= 10;
			if(f[y] > 0)f[y] --;
			else
			{
				flag = i;
				break;
			}
		}
		if(flag)break;
	}
	cout << flag - 1;
	return 0;
}

Topic description 3

Question analysis

 Note: To determine how many different straight lines there are, we need to exclude the same straight lines. We can perform violent enumeration. When

x1 == x2 or y1 == y2 is a straight line whose slope is perpendicular to or parallel to the X-axis. There are 41 lines in total. We can

Put it at the end and add it up. We enumerate all the straight lines and store them in the set. The set will automatically remove duplicates and find out the number of central lines in the set.

That’s it.

Thinking: When storing a straight line in set, we mainly store the slope and intercept. The slope and intercept determine a straight line y = kx + b.

Its slope: (y2 - y1) / (x2 - x1)

When we calculate the intercept, we cannot directly use the calculated slope to calculate because it will lose accuracy and cause errors.

#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
typedef pair<double, double> PII;
set<PII> st;
int ans;
int main()
{
	for(int x1 = 0; x1 <= 19; x1 ++)
	{
		for(int y1 = 0; y1 <= 20; y1 ++)
		{
			for(int x2 = 0; x2 <= 19; x2 ++)
			{
				for(int y2 = 0; y2 <= 20; y2 ++)
				{
					if(x1 == x2 || y1 == y2)continue;
					double k = ((y2 - y1) * 1.0) / ((x2 - x1) * 1.0);
					double b = ((x2 * y1 - x1 * y2) * 1.0) / ((x1 - x2) * 1.0);
					st.insert({k, b});
				}
			}
		}
	}
	ans = 41 + st.size();
	cout << ans;
	return 0;
}

So the answer is 40257

Guess you like

Origin blog.csdn.net/m0_75087931/article/details/133419836