跳到正文

个人记录

8-13 下午测试

_small_beswk_约 7 分钟
原文
文章信息与版本

文章信息

发布
2024年8月13日
收录
2025年12月12日
更新
2026年11月21日
篇幅
约 7 分钟

版本

  1. v1当前

kesesesesese!!今天考的真的不是很好啊啊啊(╯▔皿▔)╯




B2102

错误原因

  • 没有正确的判断不存在不存在的情况,所以导致没有正确输出notfoundnot found,痛失10分啊岂可修!!(╯▔皿▔)╯

正确思路

  • 因为长和宽只能是5,所以往死里套循环!!套他个四千五百个!!(O(n3)O(n^3))
  • 枚举每行最大和每列最小再看祂存不存在即可AC!!

正确代码

C++
#include<bits/stdc++.h>
using namespace std;
int a[10][10];
int main()
{
	for(int i = 1; i <= 5; i++)
	{
		for(int j = 1; j <= 5; j++)
		{
			cin >> a[i][j];
		}
	}
	bool flag = false;
	for(int i = 1; i <= 5; i++)
	{
		for(int j = 1; j <= 5; j++)
		{
			int maxn = 0, minn = 100000005;
			for(int k = 1; k <= 5; k++)
			{
				maxn = max(maxn, a[i][k]);
				minn = min(minn, a[k][j]);
			}
			if(maxn == a[i][j] && minn == a[i][j])
			{
				flag = true;
				cout << i << " " << j << " " << a[i][j] << "\n";
			}
		}
	}
	if(flag == false) cout << "not found";
	return 0;
}



P1897

错误原因

  • 思路没转过来啊baka而且还耗了很多时间QAQ
  • 以为顺序是固定的,其实是必须排序的啊baka

正确思路

  • 按基本思路来想就行了,用笔在草稿纸上写一写会理解的好一些

正确代码

C++
#include<bits/stdc++.h>
using namespace std;
long long a[1000005];
int main()
{
	long long n, cnt = 0, ans = 0;
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	cnt = 1;
	sort(a + 1, a + 1 + n);
	while(cnt != n + 1)
	{
		int c = a[cnt] - a[cnt - 1];
		if(c == 0) ans += 1;
		else ans += (c * 6 + 6);
		cnt++;
	}
	ans += a[cnt - 1] * 4; 
	cout << ans << endl;
	return 0;
}

P1454

错误原因

  • 好吧其实也不算错误原因因为看着样例真的好 瘆 人so没写啊啊啊啊(╬▔皿▔)凸

正确思路

-先寻找联通块数量,这里的连通块定义与其他的不同. 这里定义为曼哈顿距离不超过2的都属于一个联通块。

  • 曼哈顿距离就是标明两个点在标准坐标系上的绝对轴距总和),即∣x1−x2∣+∣y1−y2∣|x1-x2|+|y1-y2|。

正确代码

C++
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
    return 0;
}
#include<bits/stdc++.h>
using namespace std;
const int nx[15] = {0, 1, -1, 0, 0, 2, -2, 0, 0, 1, -1, 1, -1};
const int ny[15] = {0, 0, 0, 1, -1, 0, 0, 2, -2, -1, 1, 1, -1}; 
char a[1005][1005];
void dfs(int x, int y)
{
	if(x < 1 || x > n || y < 1 || y > m || a[x][y] != '#') return;
    a[x][y] = '-';
    for(int i = 1; i <= 12; i++)dfs(x + nx[i], y + ny[i]);
	return ;
}
int main()
{
	int n, m, ans = 0;
    cin >> n >> m;
    for(int i = 1; i <= n; i++) 
	{
		for(int j = 1; j <= m; j++) cin >> a[i][j];
	} 
    for(int i = 1; i <= n; i++)
	{
        for(int j = 1; j <= m; j++)
		{
            if (a[i][j] == '#')
			{
                ans++;
                dfs(i, j);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

P9050

错误原因

  • 没任何时间了啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊凸(艹皿艹 )WE DO NOT HAVE ANY TIME!!!!

正确思路

  • 用两个方向数组存好方位,方便递归判断,如果这个点没有变成‘-’或者本来就是‘-’那么就是一个新的图型所以要+1个。最后在输出答案即可啊岂可修!!!

正确代码

C++
#include <bits/stdc++.h>
using namespace std;;
long long a[500005], b[500005], n, ans;
bool check(long long x)
{
	long long ans = a[x];
	for(int i = 1; i < x; i++)
	{
		if(a[i] < ans) ans += a[i];
		else return 0;
	} 
	for(int i = x + 1; i <= n; i++)
	{
		if(ans > a[i]) ans += a[i];
		else return 0;
	}
	return 1;
}
int main()
{
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
		b[i] = a[i];
	} 
	sort(a + 1, a + n + 1);
	long long l = 1, r = n + 1, mid;
	while(l < r)
	{
		mid = (l + r) / 2;
		if(check(mid)) r = mid;
		else l = mid + 1;
	}
	if(!check(l))
	{
		for(int i = 1; i <= n; i++) cout << "N";
		return 0;
	}
	for(int i = 1; i <= n; i++)
	{
		if(b[i] >= a[l]) cout << "T";
		else cout << "N";
	}
	return 0;
}
原文