跳到正文

个人记录

7.26河西J2训练课 day02-课后总结

MAOYICONG约 10 分钟
原文

这是 2026年7月27日 存档的第 1 版,不是当前版本。查看当前版本

文章信息与版本

文章信息

发布
2026年7月27日
收录
2026年7月27日
更新
2026年11月14日
篇幅
约 10 分钟

版本

  1. v2当前
  2. v1

成绩(一坨)

T1:100分,用时1分钟
T2:0分,用时5分钟
T3:0分,用时15分钟
T4:100分,用时10分钟 T5:0分,用时20分钟 T6:0分,用时45分钟

总结

T1-解析

题意

两个时刻之间有多少分钟

思路

2424 小时制时间转分钟,相减即可

代码

C++
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define T_T ios::sync_with_stdio(0)
#define qwq cin.tie(0),cout.tie(0)
#define woyaoAKCSP return 0
#define L using
#define S namespace
#define Z std
L S Z;
signed main()
{
	T_T;
	qwq;
	int h1,h2,m1,m2;
	cin>>h1>>m1>>h2>>m2;
	int ks=h1*60+m1;
	int js=h2*60+m2;
	cout<<js-ks<<endl;
	woyaoAKCSP;
}

总结

非常简单的一道题直接缪杀好题多出。

T2-解析

题意

nn 个正整数 a1,a2,......,ana_1,a_2,...... ,a_n ,对于第i(1≤i≤n)i(1\le i \le n) 个数,是否存在x2+y2=aix^2+y^2=a_i 。

思路

一层循环版:遍历 xx ,看是否存在整数 yy 。 两层循环版:遍历 x,yx,y 。范围是 1∼n1 \sim \sqrt{n} 。 (第一版代码No写成NO了,/(ㄒoㄒ)/~~)

代码

C++
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
int n,a[15];
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		int tmp=a[i];
		bool yes=false;
		for(int x=1;x<=tmp;x++)
		{
			int b=a[i]-x*x;
			b=sqrt(b);
			if(x*x+b*b==a[i]&&b!=0) yes=true;
			if(yes==true) break;
		}
		if(yes) cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	return 0;
}

总结

主要考思路和优化 O(n2)O(n^2) 的做法。
如果输出不打错的话还能得五十分……

T3-解析

题意

给一个数对(x,y)(x,y) ,输出这个经过这个数对的同行,同列,左上到右下对角线,左下到右上对角线的格子坐标。

思路

前两个很好做,后两个需要找规律,我们可以发现:左上到右下,同一个对角线 x,yx,y 的差其实为定值。左下~右上同理,x,yx,y 的和为定值。

代码

C++
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
int n,i,j;
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>i>>j;
	for(int x=1;x<=n;x++)
	{
		cout<<"("<<i<<","<<x<<")"<<" ";
	}
	cout<<endl;
	for(int x=1;x<=n;x++)
	{
		cout<<"("<<x<<","<<j<<")"<<" ";
	}
	cout<<endl;
	//差一定,j-i值一定
	int cha=j-i;
	for(int h=1;h<=n;h++)
	{
		int l=h+cha;
		if(l>=1&&l<=n) cout<<"("<<h<<","<<l<<")"<<" ";
	} 
	int he=j+i;
	cout<<endl;
	for(int h=n;h>=1;h--)
	{
		int l=he-h;
		if(l>=1&&l<=n) cout<<"("<<h<<","<<l<<")"<<" ";
	}
	return 0;
}

总结

在做题时还是没有发现这个规律,所以用了一大堆if反而把自己绕进去了。

T4-解析

题意

nn 名同学排队,需要排成一队身高由高到低,若身高一样则看体重由重到轻。

思路

如果我们按照冒泡排序的做法来做会发现某些样例是过不了的,因为有可能,排完一遍之后还不是有序的。所以我们需要想办法。
本人做法:使用一个函数check,来遍历数组是否有序。由于数据范围只有30003000,所以两层循环是可以过的(一层排序一层检查)。

代码

C++
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int N=3005;
struct student
{
	int h,w;
}stu[N];
int n;
int check()
{
	for(int i=1;i<n;i++)
	{
		if(stu[i].h<stu[i+1].h) 
		{
			return 0;
		}
		if(stu[i].h==stu[i+1].h)
		{
			if(stu[i].w<stu[i+1].w) return 0;
		}
	}
	return 1;
}
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>stu[i].h>>stu[i].w;
	}
	int ans=0;
	while(1)
	{
		if(check()==1) break;
		for(int i=1;i<n;i++)
		{
			if(stu[i].h<stu[i+1].h) 
			{
				swap(stu[i],stu[i+1]);
				ans++;
			}
			if(stu[i].h==stu[i+1].h)
			{
				if(stu[i].w<stu[i+1].w)
				{
					swap(stu[i],stu[i+1]);
					ans++;	
				}
			}
		}	
	}
	cout<<ans<<endl;
	return 0;
}

总结

GESP的题都是思路怪。

T5-解析

题意

一共 l+1l+1 棵树,有砍树的从 l∼rl \sim r 砍掉,也有种树的从 l∼rl \sim r 种上树苗。问最终剩下了多少树苗和种上又被砍掉的树苗有多少棵。

思路

创建一个桶来存储一个位置的状态,00 表示老树,11 表示空穴,22 表示树苗。
如果是砍树的,如果砍到的地方是树苗,记录砍掉树苗的变量就要 +1+1 。同理,种完树的时候,如果种下了树苗,记录留下树苗的变量就要 +1+1 。

代码

C++
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
int l,n,ans,res;//ans最终剩下的树, res种上又被砍掉 
int tong[10005];
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>l>>n;
	memset(tong,0,sizeof(tong));//0老树,1空穴,2树苗 
	while(n)
	{
		int op,le,ri;
		cin>>op>>le>>ri;
		if(op==0)
		{
			for(int i=le;i<=ri;i++)
			{
				if(tong[i]==2) res++;
				tong[i]=1; 
			}
		}
		if(op==1)
		{
			for(int i=le;i<=ri;i++)
			{
				if(tong[i]==1) tong[i]=2;
			}
		}
		n--;
	}
	for(int i=0;i<=l;i++)
	{
		if(tong[i]==2) ans++;
	}
	cout<<ans<<endl<<res;
	return 0;
}

总结

没想到用桶存三种状态,没搞懂树苗和老树的区别。

T6-解析

题意

给定两个序列,一个入栈序列pushed,一个出栈序列poped, 已知入栈序列,如果出栈序列可能是poped输出Yes,不可能输出No。

思路

入栈序列可能不是连续的,比如1,2,3,4,51,2,3,4,5。有可能入栈 1,2,31,2,3,然后弹出 3,23,2 再继续入栈。 用一个队列和一个栈来模拟入栈出栈过程。

代码

C++
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int N=1e5+5;
int pushed[N],poped[N];

signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		for(int i=1;i<=n;i++)
		{
			cin>>pushed[i];
		}
		queue<int>q;
		for(int i=1;i<=n;i++)
		{
			int x;
			cin>>x;
			q.push(x);
		}
		stack<int>st;
		for(int i=1;i<=n;i++)
		{
			st.push(pushed[i]);
			while(q.size()&&st.size()&&st.top()==q.front())
			{
				q.pop();
				st.pop();
			}
		}
		if(q.empty()&&st.empty()) 
		{
			cout<<"Yes"<<endl;
		}
		else
		{
			cout<<"No"<<endl;
		}
	}
	return 0;
}

总结

没有想到用队列存储出栈序列这个做法。

总结

手感一坨,得注意时间和细心问题。