跳到正文

个人记录

20260718总结

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

文章信息

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

版本

  1. v1当前

20260718总结

一、比赛基本情况

  • 比赛日期:2026/7/182026/7/18
  • 比赛时长:33 小时
  • 比赛得分:201201 分
  • 比赛排名:1414 名

二、比赛整体回顾

第一题想了一下不会,然后第二题和第三题做了,第四题不会骗了点分

三、题目复盘

T1:Cow Tipping

  • 本题得分:00
  • 开始时间:8:308:30
  • 结束时间:8:408:40
  • 总用时:1010 分钟

初始思路

不会

考场代码

\

赛后题解

尝试通过正反两轮遍历数组,利用中间位置调整操作抹平相邻元素的大小差异,每当中间元素高于一侧相邻元素时计算差值,同步修改对应位置数值并累加操作代价;处理完成后检验数组所有元素是否相等且不存在负数,合法则输出总代价,不合法输出 - 1,同时单独处理 n=2 的边界情况

补题代码

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN=100001;
int n;
int a[MAXN];
unsigned long long ans=0;
void func(){
    memset(a,0x3f3f3f3f,sizeof(a));
    ans=0;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    if(n==2){
        cout<<(a[1]==a[2]?0:-1)<<"\n";
        return;
    }
    for(int i=2;i<n;i++){
        if(a[i]>a[i+1]){
            int t=a[i]-a[i+1];
            a[i-1]-=t;
            a[i]-=t;
            ans+=t*2;
        }
        if(a[i]>a[i-1]){
            int t=a[i]-a[i-1];
            a[i+1]-=t;
            a[i]-=t;
            ans+=t*2;
        }
    }
    for(int i=n-1;i>=2;i--){
        if(a[i]>a[i+1]){
            int t=a[i]-a[i+1];
            a[i-1]-=t;
            a[i]-=t;
            ans+=t*2;
        }
        if(a[i]>a[i-1]){
            int t=a[i]-a[i-1];
            a[i+1]-=t;
            a[i]-=t;
            ans+=t*2;
        }
    }
    for(int i=1;i<n;i++){
        if(a[i]!=a[i+1]||a[i]<0){
            cout<<-1<<"\n";
            return;
        }
    }
    cout<<ans<<"\n";
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--)func();
    return 0;
}

复杂度

  • 时间复杂度:O(tn)O(tn)
  • 空间复杂度:O(n)O(n)

Transitive Dice

  • 本题得分:100100
  • 开始时间:8:408:40
  • 结束时间:10:0010:00
  • 总用时:11 小时 2020 分钟

初始思路

暴力枚举

考场代码

C++
#include<bits/stdc++.h>
using namespace std;
int read(){
	char ch=getchar();
	int num=0,f=1;
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){num=num*10+ch-'0';ch=getchar();}
	return f*num;
}
int t,a[10],b[10],c[10];
int main(){
	t=read();
	while(t--){
		bool f=0;
		int s1=0,s2=0,w;
		a[1]=read(),a[2]=read(),a[3]=read(),a[4]=read();
		b[1]=read(),b[2]=read(),b[3]=read(),b[4]=read();
		for(int i=1;i<=4;i++){
            for(int j=1;j<=4;j++){
				if(a[i]>b[j])s1++;
				if(b[j]>a[i])s2++;
			}
		}
		if(s1>s2)w=1;
		else if(s2>s1)w=2;
		else{
			cout<<"no";
			continue;
		}
		for(int i=1;i<=10;i++){
			c[1]=i;
			for(int j=1;j<=10;j++){
				c[2]=j;
				for(int k=1;k<=10;k++){
					c[3]=k;
					for(int p=1;p<=10;p++){
						c[4]=p;
					    int c1=0,c2=0;
						if(w==1){
							for(int l=1;l<=4;l++){
								for(int r=1;r<=4;r++){
									if(c[l]>a[r])c1++;
									else if(a[r]>c[l])c2++;
								}
							}
							if(c2>=c1)continue;
							c2=c1=0;
							for(int l=1;l<=4;l++){
								for(int r=1;r<=4;r++){
									if(c[l]>b[r])c1++;
									else if(b[r]>c[l])c2++;
								}
							}
							if(c1>=c2)continue;
							f=1;
						}else{
							for(int l=1;l<=4;l++){
								for(int r=1;r<=4;r++){
									if(c[l]>a[r])c1++;
									else if(a[r]>c[l])c2++;
								}
							}
							if(c2<=c1)continue;
							c2=c1=0;
							for(int l=1;l<=4;l++){
								for(int r=1;r<=4;r++){
									if(c[l]>b[r])c1++;
									else if(b[r]>c[l])c2++;
								}
							}
							if(c1<=c2)continue;
							f=1;
						}
					}
				}
				if(f)break;
			}
			if(f)break;
		}
		if(f)cout<<"yes\n";
		else cout<<"no\n";
	}
	return 0;
}

赛后题解

AC了所以就是: 暴力枚举

补题代码

\

复杂度

  • 时间复杂度:O(t)O(t) (常数)
  • 空间复杂度:O(1)O(1) (常数)

T3 :Herdle

  • 本题得分:9191
  • 开始时间:10:0010:00
  • 结束时间:11:0011:00
  • 总用时:11 小时

初始思路

先读取 3×3 的目标方阵,利用 map 统计每种字符出现的数量。接着逐个读取猜测方阵中的字符,如果当前位置字符与目标相同,c 加一并减少 map 中该字符计数;如果位置不同但 map 里还有剩余该字符,o 加一并减少对应计数。最后输出 c 和 o。

考场代码

C++
#include<bits/stdc++.h>
using namespace std;
char a[5][5];
map<char,int>mp;
int main(){
	freopen("herdle.in","r",stdin);
	freopen("herdle.out","w",stdout);
	for(int i=1;i<=3;i++)
		for(int j=1;j<=3;j++){
			cin>>a[i][j];
			mp[a[i][j]]++;
		}
	int c=0,o=0;
	for(int i=1;i<=3;i++){
		for(int j=1;j<=3;j++){
			char ch;
			cin>>ch;
			if(a[i][j]==ch){
				c++;
				mp[ch]--;
			}
			else if(mp[ch]){
				o++;
				mp[ch]--;
			}
		}
	}
	cout<<c<<"\n"<<o;
	return 0;
}

赛后题解

该代码读取两个 3×3 字符矩阵,借助 map 统计字符数量,分两轮遍历分别统计位置完全一致的字符数量 c、字符存在但位置不一致的字符数量 o

补题代码

C++

复杂度

  • 时间复杂度:O(1)O(1)
  • 空间复杂度:O(1)O(1)

T4: Flowerpot S

  • 本题得分:1010
  • 开始时间:11:0011:00
  • 结束时间:11:1011:10
  • 总用时:1010 分

初始思路

骗分

考场代码

C++
#include<bits/stdc++.h>
using namespace std;

int main(){
	freopen("fpot.in","r",stdin);
	freopen("fpot.out","w",stdout);
	cout<<-1;
	return 0;
}

赛后题解

先将点按横坐标排序,双指针划定横坐标区间,利用两个单调队列实时维护区间内 y 坐标的最大值与最小值;当区间 y 极差大于等于 d 时更新横坐标最小差值,并向右移动左边界收缩区间,最终输出答案。

补题代码

C++
#include<bits/stdc++.h>
using namespace std;
int n,d;
struct node{int x,y;};
bool cmp(node x,node y){return x.x<y.x;}
int main(){
    cin>>n>>d;
    vector<node>a(n+5);
    for(int i=1;i<=n;i++)cin>>a[i].x>>a[i].y;
    sort(a.begin()+1,a.begin()+n+1,cmp);
    list<int>q1,q2;
    int l=1,ans=2e9;
    for(int r=1;r<=n;r++){
        while(!q1.empty()&&a[r].y>=a[q1.back()].y)q1.pop_back();
        q1.push_back(r);
        while(!q2.empty()&&a[r].y<=a[q2.back()].y)q2.pop_back();
        q2.push_back(r);
        while(a[q1.front()].y-a[q2.front()].y>=d){
            ans=min(ans,a[r].x-a[l].x);
            if(q1.front()==l)q1.pop_front();
            if(q2.front()==l)q2.pop_front();
            l++;
        }
    }
    cout<<(ans==2e9?-1:ans);
    return 0;
}

复杂度

  • 时间复杂度:O(n log n)O(n~log~n)
  • 空间复杂度:O(n)O(n)

四、整体反思

做得较好的地方

稍微有改进

需要改进的地方

认真审题

时间安排总结

蛮好的

原文