跳到正文

个人记录

10.30-甜菜测试-410-课堂总结

Yuese_约 11 分钟
原文
文章信息与版本

文章信息

发布
2026年11月3日
收录
2026年11月5日
更新
2026年11月22日
篇幅
约 11 分钟

版本

  1. v2当前
  2. v1

10.30-甜菜测试-410-课堂总结

T1 P17714 [HexOI Round 1] 长安城 / city

考察知识点
  • I don′t  know.I\ don't\ \ know.

❌️错误原因:{\color{red}错误原因:}

  • 细节错误

❌️错误思路:{\color{red}错误思路:}

  • 两个点的距离为横坐标减横坐标的绝对值加纵坐标减纵坐标的绝对值,找到每个点到起点的距离,找到最小的,输出

❌️错误代码(Unaccepted  80分):{\color{red} 错误代码(}{\color{red}Unaccepted\ \ \color{Green}80分 }\color{red}):

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n,x,y;
	cin>>n>>x>>y;
	int sum=INT_MAX;
	while(n--){
		int xx,yy;
		cin>>xx>>yy;
		sum=min(sum,abs(xx-x)+abs(yy-y));
	}
	cout<<sum;
	return 0;
}

✅️正确思路:{\color{green}正确思路:}

  • 因为答案是109+(−109)×210^9+(-10^9)\times2的,所以INT_MAX不够用

✅️正确代码(Accepted  100分):{\color{green} 正确代码(}{\color{green} Accepted\ \ 100分}\color{green}):

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n,x,y;
	cin>>n>>x>>y;
	int sum=LONG_LONG_MAX;//最大值开大一点
	while(n--){
		int xx,yy;
		cin>>xx>>yy;
		sum=min(sum,abs(xx-x)+abs(yy-y));//计算距离 
	}
	cout<<sum;
	return 0;
}

T2 P17728 [SCP-J 2026] 染色 / color

考察知识点
  • 前缀最小值

❌️错误原因:{\color{red}错误原因:}

  • 骗分

❌️错误思路:{\color{red}错误思路:}

  • 骗分

❌️错误代码(Unaccepted  0分):{\color{red} 错误代码(}{\color{Red} Unaccepted\ \ 0分}\color{red}):

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout<<"7";
	return 0;
}

✅️正确思路:{\color{green}正确思路:}

  • 先简化问题,只有一种颜色,答案是a2−a1+a3−a2+...+an−an−1=an−a1a_2-a_1+a_3-a_2+...+a_n-a_{n-1}=a_n-a_1所以一种颜色的答案只跟第一个点和最后一个点有关

其他如图所示:

✅️正确代码(Accepted   100分):{\color{green} 正确代码(}{\color{green}Accepted \ \ \ 100分}\color{green}):

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
int a[500005];
signed main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
    	cin>>a[i];
	}
    int sum=0,minn=a[2];
	for(int i=2;i<n;i++){//方案一       
        sum=max(sum,a[i]-minn);//求最大值
        minn=min(a[i],minn); //前缀最小值,用一个数减前面最小的数
	}
    for(int i=1;i<n;i++){
        sum =max(sum,a[i]-a[i+1]);//方案二:刚刚好拼上
	}
    cout<<a[n]-a[1]+max(0LL,sum);//和0求最大值,因为可以只涂一种颜色
	return 0;
}

T3 P17687 [IO 2025 #2] 尼基塔与钓鱼

考察知识点
  • 双指针

❌️错误原因:{\color{red}错误原因:}

  • 细节错误

❌️错误思路:{\color{red}错误思路:}

  • 用双指针找到所以符合条件的区间,输出最大鱼数

❌️错误代码(Unaccepted  0分):{\color{red} 错误代码(}{\color{Red} Unaccepted\ \ 0分}\color{red}):

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
int a[100005],sum,b[100005];
signed main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,q;
    cin>>n>>q;
    for(int i=1;i<=n;i++){
    	cin>>a[i];
	}
	while(q--){
		int x;
		cin>>x;
		if(b[x]==1){
			if(a[x]==1)sum--;
		}
		else{
			if(a[x]==1)sum++;
			else if(sum>0){
				a[x]=1;
				sum++;
			}
		}
	}
	for(int i=1;i<=n;i++){
		cout<<a[i]<<' ';
	}
	return 0;
}

✅️正确思路:{\color{green}正确思路:}

  • 同上

✅️正确代码(Accepted   100分):{\color{green} 正确代码(}{\color{green} Accepted \ \ \ 100分}\color{green}):

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
int a[1000005];
signed main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++){
    	cin>>a[i];
	}
	sort(a+1,a+n+1);
	int l=1,r=1,sum=LONG_LONG_MIN;
	while(r<=n&&l<=n){
		if(a[r]-a[l]<=k){//区间长度满足长度要求
			r++;
            sum=max(sum,r-l);//注意!满足条件也要计算答案,否则如果最大满足条件区间是整个数组不会进入下一个条件,就没法计算答案
		}
		else{//区间长度不满足长度要求
			sum=max(sum,r-l);//计算答案
			l++;
		}
	}
	cout<<sum;
	return 0;
}

T4 P14659 病毒传播

考察知识点
  • 队列
  • 模拟

❌️错误原因:{\color{red}错误原因:}

  • ❓️天知道什么错误❓️

❌️错误思路:{\color{red}错误思路:}

  • 定义一个感染源数量变量,每一个感染了的人摘下/戴上口罩,该变量就加一/减一,如果一个没有被感染的人摘下口罩,如果感染源变量大于0,这个人就会被感染

❌️错误代码(Unaccepted  0分):{\color{red} 错误代码(}{\color{Red} Unaccepted\ \ 0分}\color{red}):

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
int a[100005];
signed main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++){
    	cin>>a[i];
	}
	sort(a+1,a+n+1);
	int l=1,r=1,sum=0;
	while(r<=n&&l<=n){
		if(a[r]-a[l]<=k){
			r++;
		}
		else{
			sum=max(sum,r-l);
			l++;
		}
	}
	cout<<sum;
	return 0;
}

✅️正确思路:{\color{green}正确思路:}

  • 同上

✅️正确代码(Accepted   100分):{\color{green} 正确代码(}{\color{green} Accepted \ \ \ 100分}\color{green}):

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
int a[1000005],sum,b[1000005];
signed main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,Q;
    cin>>n>>Q;
    for(int i=1;i<=n;i++){
    	cin>>a[i];
        b[i]=1;
	}
    queue<int>q;
	while(Q--){
		int x;
		cin>>x;
		b[x]=1-b[x];
        if(b[x]==0){//摘口罩
            if(a[x]==1)sum++;//是感染源
            else q.push(x);//不是
        }
        else{//戴口罩
            if(a[x]==1)sum--;//是感染源
        }
        if(sum>0){
            while(q.size()){//遍历所有摘口罩的人,进行感染,因为有人摘了口罩,然后一直没带,后来有感染源摘了口罩,也要被感染
                if(b[q.front()]==0){
                    if(a[q.front()]==0)sum++;
                    a[q.front()]=1;
                }
                q.pop();
            }
        }
	}
	for(int i=1;i<=n;i++){//输出结果
		cout<<a[i]<<' ';
	}
	return 0;
}

这篇文章很水

原文