跳到正文

个人记录

8.22-407-模拟考

AC_Goose约 6 分钟
原文
文章信息与版本

文章信息

发布
2025年8月22日
收录
2025年12月12日
更新
2026年11月16日
篇幅
约 6 分钟

版本

  1. v1当前

8.22-407-模拟考

T1 大楼

题意简化

给你一个数组,让你求出第一个大于a1a_1的值的下标。

代码

C++
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int N=105;
int n;
int h[N];
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>h[i];
	}
	int tmph=h[1];
	for(int i=2;i<=n;i++){
		if(h[i]>tmph){
			cout<<i;
			return 0;
		}
	}
	cout<<-1;
	return 0;
}

T2 盲打练习

题意发现

给你两个字符串,一个是标准字符串,一个是错误字符串。问你哪些字符在两个字符串之中都有,并输出下标。

我们都有一个opop,代表判断到了第opop个字符。循环一遍错误字符串,先找有没有标准字符串的第一个,找到了就输出,并op+=1op+=1。

代码

C++
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
string s,t;
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>s>>t;
	int op=0;
	int tmp=s[op];
	for(int i=0;i<t.size();i++){
		if(t[i]==tmp){
			cout<<i+1<<' ';
			op++;
			tmp=s[op];
		}
	}
	return 0;
}

T3 小A的口头禅

题意分析

给你一个矩阵,让你输出有几个hehe。

第一眼看成了深搜,但其实数据不大,可以暴力。

我们先枚举每一个点,然后再判断能不能向这个发现搜索,也就是判断越界。

代码

C++
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int N=1005;
int n,m;
char c[N][N];
bool vis[N][N];
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
int ans;
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>c[i][j];
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(j+4<=m+1){
				if(c[i][j]=='h'&&c[i][j+1]=='e'&&c[i][j+2]=='h'&&c[i][j+3]=='e'){
					ans++;
				}
			}
			if(j-4>=0){
				if(c[i][j]=='h'&&c[i][j-1]=='e'&&c[i][j-2]=='h'&&c[i][j-3]=='e'){
					ans++;
				}
			}
			if(i+4<=n+1){
				if(c[i][j]=='h'&&c[i+1][j]=='e'&&c[i+2][j]=='h'&&c[i+3][j]=='e'){
					ans++;
				}
			}
			if(i-4>=0){
				if(c[i][j]=='h'&&c[i-1][j]=='e'&&c[i-2][j]=='h'&&c[i-3][j]=='e'){
					ans++;
				}
			}
		}
	}
	cout<<ans;
	return 0;
}

T4 调酒大师

题意分析

这一题可以使用二分答案。

单调性分析

假设我们求出了答案xx,那么x+1x+1杯一定不行,x+2x+2杯更不行。但是x−1x-1可以。

但是,我们的检查函数怎么写?

如果果汁的数量小于midmid或白酒的数量小于midmid或果汁和白酒的和小于mid∗4mid*4就不行。

代码

C++
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
int T;
int n,m;
bool check(int mid){
	if(n<mid||m<mid||(n+m)<mid*4){
		return 0;
	}
	return 1;
} 
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>T;
	while(T--){
		cin>>n>>m;	
		int l=0,r=1e9+1;
		while(l+1<r){
			int mid=(l+r)/2;
			if(check(mid)){
				l=mid;
			}else{
				r=mid;
			}
		}
		cout<<l<<endl;
	}
	return 0;
}
原文