跳到正文

个人记录

2.24-小六集训队-407

David_Lu约 15 分钟
原文
文章信息与版本

文章信息

发布
2026年2月24日
收录
2026年2月24日
更新
2026年11月16日
篇幅
约 15 分钟

版本

  1. v3当前
  2. v2
  3. v1

T735760 小落的大鹅

题意

2626只大鹅玩井字棋,每只大鹅的棋子是2626个大写英文字母,游戏规则和原版井字棋规则多了三条。一、所有大鹅都可以参与。二、两只大鹅可以组队。三、当有一行、一列、一对角线上的棋子只有两种或一种,对应的大鹅或小队获胜

输入一个已经占满了的井字棋棋盘

输出有多只大鹅和小队获胜

思路

直接将判断行,列,对角线分别做成三个函数,用两个桶分别记录单个获胜和小队获胜,统计小队获胜要用二位桶,小队的统计要将两位成员分别存入两个值里,因为就算调换顺序还是同一小队,注意结果要除二

AC代码

C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
char a[5][5];
int ans1, ans2;
bool t[26];
bool t2[26][26];
void col(int x){//行
	if(a[x][1] == a[x][2] and a[x][1] == a[x][3]){
		t[a[x][1] - 'A'] = true;
	}else if(a[x][1] == a[x][2]){
		t2[a[x][1] - 'A'][a[x][3] - 'A'] = true;
		t2[a[x][3] - 'A'][a[x][1] - 'A'] = true;
	}else if(a[x][1] == a[x][3]){
		t2[a[x][1] - 'A'][a[x][2] - 'A'] = true;
		t2[a[x][2] - 'A'][a[x][1] - 'A'] = true;
	}else if(a[x][3] == a[x][2]){
		t2[a[x][1] - 'A'][a[x][2] - 'A'] = true;
		t2[a[x][2] - 'A'][a[x][1] - 'A'] = true;
	}
}
void wol(int x){//列
	if(a[1][x] == a[2][x] and a[1][x] == a[3][x]){
		t[a[1][x] - 'A'] = true;
	}else if(a[1][x] == a[2][x]){
		t2[a[1][x] - 'A'][a[3][x] - 'A'] = true;
		t2[a[3][x] - 'A'][a[1][x] - 'A'] = true;
	}else if(a[1][x] == a[3][x]){
		t2[a[1][x] - 'A'][a[2][x] - 'A'] = true;
		t2[a[2][x] - 'A'][a[1][x] - 'A'] = true;
	}else if(a[3][x] == a[2][x]){
		t2[a[1][x] - 'A'][a[2][x] - 'A'] = true;
		t2[a[2][x] - 'A'][a[1][x] - 'A'] = true;
	}
}
void d1(){//对角线1
	if(a[1][1] == a[2][2] and a[1][1] == a[3][3]){
		t[a[1][1] - 'A'] = true;
	}else if(a[1][1] == a[2][2]){
		t2[a[1][1] - 'A'][a[3][3] - 'A'] = true;
		t2[a[3][3] - 'A'][a[1][1] - 'A'] = true;
	}else if(a[1][1] == a[3][3]){
		t2[a[1][1] - 'A'][a[2][2] - 'A'] = true;
		t2[a[2][2] - 'A'][a[1][1] - 'A'] = true;
	}else if(a[3][3] == a[2][2]){
		t2[a[1][1] - 'A'][a[2][2] - 'A'] = true;
		t2[a[2][2] - 'A'][a[1][1] - 'A'] = true;
	}
}
void d2(){//对角线2
	if(a[1][3] == a[2][2] and a[1][3] == a[3][1]){
		t[a[1][3]] = true;
	}else if(a[1][3] == a[2][2]){
		t2[a[3][1] - 'A'][a[2][2] - 'A'] = true;
		t2[a[2][2] - 'A'][a[3][1] - 'A'] = true;
	}else if(a[1][3] == a[3][1]){
		t2[a[1][3] - 'A'][a[2][2] - 'A'] = true;
		t2[a[2][2] - 'A'][a[1][3] - 'A'] = true;
	}else if(a[3][1] == a[2][2]){
		t2[a[3][1] - 'A'][a[2][2] - 'A'] = true;
		t2[a[2][2] - 'A'][a[1][3] - 'A'] = true;
	}
}
signed main(){
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	for(int i = 1;i <= 3;i++){
		for(int j = 1;j <= 3;j++){
			cin >> a[i][j];
		}
	}
	for(int i = 1;i <= 3;i++){
		col(i);
		wol(i);
	}
	d1();
	d2();
	for(int i = 0;i < 26;i++){
		if(t[i] == true){
			ans1++;
		}
	}
	cout << ans1<< '\n';
	for(int i = 0;i < 26;i++){
		for(int j = 0;j < 26;j++){
			if(t2[i][j] == true){
				ans2++;
			}
		}
	}
	cout << ans2 / 2<< '\n';
	return 0;
}

T735764 数矩形

题意

有nn个在二维坐标图上的点,请问能组成多少个矩形,点能重叠

思路

普通枚举思路

最好的方法就是枚举44个点,看看能不能组成矩形

普通枚举AC代码

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 10;
struct P{
	int x, y;
}a[N];
bool cmp(P a, P b) {
	if(a.x != b.x){
		return a.x < b.x;
	}
	return a.y < b.y;
}
int n, ans;
signed main(){
	cin >> n;
	for (int i = 1;i <= n;i++){
		cin >> a[i].x>> a[i].y;
	}
	sort(a + 1, a + 1 + n, cmp);
	for(int i = 1;i <= n;i++){
		for(int j = i + 1;j <= n;j++){
			for(int k = j + 1;k <= n;k++){
				for(int l = k + 1;l <= n;l++){
					if(a[i].x == a[j].x && a[i].y == a[k].y && a[l].x == a[k].x && a[l].y == a[j].y){
						ans++;
					}
				}
			}
		}
	}
	cout << ans;
	return 0;
}

我们其实并不用枚举四个点,只要枚举对角线,因为只要有了一条对角线的坐标,就可以知道剩下两个点的坐标

AC代码

C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
pair <int, int> a[200005];
int n;
map <pair <int, int>, bool> mp;
int ans;
signed main(){
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for(int i = 1;i <= n;i++){
		cin >> a[i].first>> a[i].second;
		mp[{a[i].first, a[i].second}] = 1;
	}
	for(int i = 1;i <= n;i++){
		for(int j = i;j <= n;j++){
			if(a[i].first < a[j].first && a[i].second < a[j].second){
				if(mp.count({a[i].first, a[j].second}) == 1 and mp.count({a[j].first, a[i].second}) == 1){
					ans++;
				}
			}
		}
	}
	cout << ans;
	return 0;
}

T735761 大鹅要体检

题意

有两个数组aa和bb,可以反转aa数组一次,请求出使得恰好cc头大鹅被检查的不同操作的数量

思路

普通枚举思路

先预处理出所有每个位置相同的数量,再进行枚举任意区间反转后的情况,

普通枚举AC代码

C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n;
int a[7505], b[7505];
int ans[7505], cnt;
signed main(){
	cin>>n;
	for(int i = 1;i <= n;i++){
		cin >> a[i];
	}
	for(int i = 1;i <= n;i++){
		cin >> b[i];
	}
	for(int i = 1;i <= n;i++){
		if(a[i] == b[i]){
			cnt++;
		}
	}
	for(int l = 1;l <= n;l++){
		for(int r = l;r <= n;r++){
			int t = cnt;
			for(int i = l;i <= r;i++){
				if(a[i] == b[i]){
					t--;
				}
				if(a[i] == b[r - (i - l)]){
					t++;
				}
			}
			ans[t]++;
		}
	}
	for(int i = 0;i <= n;i++){
		cout << ans[i]<< '\n';
	}
	return 0;
}

我们可以把枚举区间改成以一个或两个地方为中心点向外扩散,再进行各项判断,之所以可以通过枚举中点向外扩散,因为这两道题都是要统计区间对称点的信息

AC代码

C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n;
int a[7505], b[7505], ans[7505];
int cnt;
signed main(){
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for(int i = 1;i <= n;i++){
		cin >> a[i];
	}
	for(int i = 1;i <= n;i++){
		cin >> b[i];
	}
	for(int i = 1;i <= n;i++){
		if(a[i] == b[i]){
			cnt++;
		}
	}
	for(int i = 1;i <= n;i++){
		int t = cnt;
		int l = i, r = i;
		while(l >= 1 and r <= n){
			if(a[l] == b[l] && a[l] != b[r]){
				t--;
			}
			if(a[r] == b[r] && a[r] != b[l]){
				t--;
			}
			if(a[l] != b[l] && a[l] == b[r]){
				t++;
			}
			if(a[r] != b[r] && a[r] == b[l]){
				t++;
			}
			ans[t]++;
			l--;
			r++;
		}
		if(i == n){
			break;
		}
		t = cnt;
		l = i, r = i + 1;
		while(l >= 1 and r <= n){
			if(a[l] == b[l] && a[l] != b[r]){
				t--;
			}
			if(a[r] == b[r] && a[r] != b[l]){
				t--;
			}
			if(a[l] != b[l] && a[l] == b[r]){
				t++;
			}
			if(a[r] != b[r] && a[r] == b[l]){
				t++;
			}
			ans[t]++;
			l--;
			r++;
		}
	}
	for(int i = 0;i <= n;i++){
		cout << ans[i]<< '\n';
	}
	return 0;
}

T735763 洛基山脉

题意

有一个数组aa,它有一个整齐度,整齐度等于每对等距山峰的高度差的绝对值之和,可以选择一段连续的区间,删去区间的左右两边,以此减少整齐度。求选择不同数量的区间时,最低的整齐度是多少

思路

可以像上一题一样,来枚举中点,再用双指针向外扩散即可

AC代码

C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 5e3 + 10;
int n;
int a[N], t[N];
signed main(){
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	memset(t, 0x3f, sizeof t);
	cin >> n;
	for(int i = 1;i <= n;i++){
		cin >> a[i];
	}
	for(int i = 2;i < n;i++){
		int l = i, r = i, sum = 0;
		while(l >= 1 && r <= n){
			sum += abs(a[l] - a[r]);
			t[r - l + 1] = min(t[r - l + 1], sum);
			l--;
			r++;
		}
	}
	for(int i = 1;i < n;i++){
		int l = i, r = i + 1, sum = 0;
		while(l >= 1 && r <= n){
			sum += abs(a[l] - a[r]);
			t[r - l + 1] = min(t[r - l + 1], sum);
			l--;
			r++;
		}
	}
	t[1] = 0;
	for(int i = 1;i <= n;i++){
		cout << t[i]<< ' ';
	}
	return 0;
}

P3407 散步

题意

nn个人在散步,每秒走11米,有的是往东,有的是往西,当两人相遇时或者遇到了相遇的人就会停下聊天,请问tt秒后,询问qq个人的位置

暴力思路

模拟每人一秒后的情况,用ss数组记录是否停下,用qq数组记录每个人的位置

暴力代码

C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 100005;
int a[N], r[N];
long long p[N];
bool s[N];
int n, t, q;
signed main(){
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n>> t>> q;
	for(int i = 1;i <= n;i++){
		cin >> a[i]>> r[i];
		p[i] = a[i];
		s[i] = false;
	}
	if(t < 0){
		t = 0;
	}
	for(int i = 0;i < t;i++){
		for(int j = 1;j <= n;j++){
			if(!s[j]){
				if(r[j] == 1){
					p[j]++;
				}else{
					p[j]--;
				}
			}
		}
		for(int j = 1;j < n;j++){
			if(p[j] == p[j + 1]){
				s[j] = true;
				s[j + 1] = true;
			}
		}
	}
	while(q--){
		int x;
		cin >> x;
		cout << p[x]<< '\n';
	}
	return 0;
}
原文