跳到正文

个人记录

比赛总结7.27

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

文章信息

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

版本

  1. v1当前

比赛总结:

T1:

题意:

告诉我们两个时间,要求我们求中间经过了多少时间

思路:

把时间转换成分钟,计算差值输出即可。

我的AC代码:

C++
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int a1,b1,a2,b2,ans1,ans2;
	cin>>a1>>b1>>a2>>b2;
	ans1=a1*60+b1;
	ans2=a2*60+b2;
	cout<<ans2-ans1;
    return 0;
}

T2:

题意:

小杨有 n 个正整数 a 1 ​ ,a 2 ​ ,…,a n ​ ,他想知道对于所有的 i(1≤i≤n),是否存在两个正整数 x 和 y 满足 x×x+y×y=a i ​

思路:

枚举x和y的所有可能情况,计算是否相等,是则输出Yes,否则输出no。

我的AC代码:

C++
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		int m,f=1;
		cin>>m;
		for(int i=1;i<=m;i++){
			for(int j=1;j<=m/i;j++){
				if(i*i+j*j==m){
					cout<<"Yes"<<endl;
					f=0;
					break;
				}
			}
			if(f==0){
				break;
			}
		}
		if(f==1){
			cout<<"No"<<endl;
		}
		f=1;
	}
    return 0;
}

T3:

题意:

输入三个自然数 N,i,j(1≤i≤n,1≤j≤n),输出在一个 N×N 格的棋盘中(行列均从 1 开始编号),与格子 (i,j) 同行、同列、同一对角线的所有格子的位置。

如:n=4,i=2,j=3 表示了棋盘中的第二行第三列的格子,

当 n=4,i=2,j=3 时,输出的结果是:

(2,1)(2,2)(2,3)(2,4) 同一行上格子的位置。

(1,3)(2,3)(3,3)(4,3) 同一列上格子的位置。

(1,2)(2,3)(3,4) 左上到右下对角线上的格子的位置。

(4,1)(3,2)(2,3)(1,4) 左下到右上对角线上的格子的位置。

思路:

枚举数组,判断位置,输出。

我的AC代码:

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

T4:

题意:

体育课上有 n 名同学排成一队,从前往后数第 i 位同学的身高为 h i ​ ,体重为 w i ​ 。目前排成的队伍看起来参差不齐,老师希望同学们能按照身高从高到低的顺序排队,如果身高相同则按照体重从重到轻排序。在调整队伍时,每次只能交换相邻两位同学的位置。老师想知道,最少需要多少次交换操作,才能将队伍调整成目标顺序。

思路:

通过冒泡排序,累计次数,输出即可。

我的AC代码:

C++
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
struct st{
	int h,w;
}a[3005];
int cmp(st x,st y){
	if(x.h==y.h){
		return x.w<y.w;
	}
	return x.h<y.h;
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i].h>>a[i].w;
	}
	int ans=0;
	for(int i=1;i<=n;i++){//第i次进行交换
	 
		for(int j=1;j<=n-i;j++){//每一次交换的操作 
			if(cmp(a[j],a[j+1])==1){
				swap(a[j],a[j+1]);
				ans++;
			}
		}
	}
	cout<<ans;
    return 0;
}

T5:

题意:

校门外马路上本来从编号 0 到 L,每一编号的位置都有一棵树。有砍树者每次从编号 A 到 B 处连续砍掉每一棵树,就连树苗也不放过(记 0 A B,含 A 和 B);幸运的是还有植树者每次从编号 C 到 D 中凡是空穴(树被砍且还没种上树苗或树苗又被砍掉)的地方都补种上树苗(记 1 C D,含 C 和 D);问最终校门外留下的树苗多少棵?植树者种上又被砍掉的树苗有多少棵?

思路:

模拟+输出。

我的AC代码:

C++
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
int a[10005];
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int l,n,ans1=0;
	cin>>l>>n;
	for(int i=0;i<=l;i++){
		a[i]=1;
	}
	for(int i=1;i<=n;i++){
		int x,y,z;
		cin>>x>>y>>z;
		if(x==0){
			for(int i=y;i<=z;i++){
				if(a[i]==2){
					ans1++;
				}
				a[i]=0;
			}
		}else{
			for(int i=y;i<=z;i++){
				if(a[i]!=1){
					a[i]=2;
				}
			}
		}
	}
	int ans=0;
	for(int i=0;i<=l;i++){
		if(a[i]==2){
			ans++;
		}
	}
	cout<<ans<<endl<<ans1;
    return 0;
}
原文