2023牛客第八场补题报告A H J K

2023牛客第八场补题报告A H J K

A-Alive Fossils_2023牛客暑期多校训练营8 (nowcoder.com)

思路

统计字符串,取出现次数为t的。

代码

#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define fi first
#define sc second

using namespace std;
const int INF = 0x3f3f3f3f3f3f3f3f;
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
typedef pair<int, int> PII;
int n;
int a[N];

map<string, int> mp;
void solve() {
  cin >> n;
  while (n--) {
    string s;
    cin >> s;
    mp[s]++;
  }
}

signed main() {
  IOS;
  int t = 1;
  cin >> t;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  set<string> res;
  for (auto [i, j] : mp) {
    if (j == t) res.insert(i);
  }
  cout << res.size() << "\n";
  for (auto i : res) cout << i << "\n";
}

H-Insert 1, Insert 2, Insert 3, …_2023牛客暑期多校训练营8 (nowcoder.com)

思路

注意到其实确定了最左边和最右边,其间的区间都可以作为右端点,所以就是需要找到每次最远的右端点,用栈一层层维护。

代码

#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve();
signed main(){
	cin.sync_with_stdio(0);
	cin.tie(0);
	int T = 1;
	//cin >> T;
	while(T--){
		solve();
	}
	return 0;
}

#define N 1001000
vector<int> q, stk[N];
int ban[N], a[N];
void solve(){
	int n;
	cin >> n;
	for(int i = 1;i <= n;i++){
		cin >> a[i];
	}
	q.push_back(n + 1);
	int ans = 0;
	for(int i = n;i >= 1;i--){
		if(stk[a[i] + 1].size()){
			ban[stk[a[i] + 1].back()] = 1;
			stk[a[i] + 1].pop_back();
		}
		if(a[i] > 1){
			q.push_back(i);
			stk[a[i]].push_back(i);
		}
		while(ban[q.back()] == 1)q.pop_back();
		ans += q.back() - i;
	}
	cout << ans << "\n";
}

J-Permutation and Primes_2023牛客暑期多校训练营8 (nowcoder.com)

思路

直接考虑枚举,我的想法是考虑3的等差数列,然后考虑三个等差数列中间怎样衔接,最终枚举得出答案。

代码

#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define fi first
#define sc second

using namespace std;
const int INF = 0x3f3f3f3f3f3f3f3f;
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
typedef pair<int, int> PII;
int n;
int a[N];

bool check(int m) {
  for (int i = 2; i * i <= m; i++) {
    if (m % i == 0) return 0;
  }
  return 1;
}

void solve() {
  cin >> n;
  vector<int> res;
  if (n % 3 == 2) {
    // 5 2单独考虑
    if (n == 5) {
      cout << "5 2 1 4 3\n";
      return;
    }
    if (n == 2) {
      cout << "1 2\n";
      return;
    }
    res.push_back(n - 2);
    res.push_back(n - 5);
    for (int i = n; i > 0; i -= 3) res.push_back(i);
    for (int i = 1; i <= n; i += 3) res.push_back(i);
    for (int i = n - 8; i > 0; i -= 3) res.push_back(i);
    for (auto i : res) cout << i << " ";
    cout << "\n";
  } else if (n % 3 == 1) {
    // n - 1 n - 4??(2 1 0)
    //(n - 2)%3 == 2
    if (n == 1) {
      cout << 1 << "\n";
      return;
    }
    if (n == 4) {
      cout << "4 1 2 3\n";
      return;
    }
    if (n == 7) {
      cout << "1 2 3 4 7 6 5\n";
      return;
    }
    if (n == 10) {
      cout << "1 2 3 4 7 6 5 8 9 10\n";
      return;
    }
    res.push_back(n - 2);
    res.push_back(n - 5);
    res.push_back(n - 8);
    res.push_back(n - 1);
    res.push_back(n - 4);
    res.push_back(n - 11);
    for (int i = n - 14; i > 0; i -= 3) res.push_back(i);
    for (int i = 1; i <= n; i += 3) res.push_back(i);
    for (int i = n - 7; i > 0; i -= 3) res.push_back(i);
    for (auto i : res) cout << i << " ";
    cout << "\n";
  } else {
    // n-1%3==2
    // n n-3 n-6
    // 3 6
    if (n == 3) {
      cout << "1 2 3\n";
      return;
    }
    if (n == 6) {
      cout << "6 5 2 1 4 3\n";
      return;
    }
    res.push_back(n);
    res.push_back(n - 3);
    res.push_back(n - 6);
    for (int i = n - 1; i > 0; i -= 3) res.push_back(i);
    for (int i = 1; i <= n; i += 3) res.push_back(i);
    for (int i = n - 9; i > 0; i -= 3) res.push_back(i);
    for (auto i : res) cout << i << " ";
    cout << "\n";
  }
}

signed main() {
  IOS;
  int t = 1;
  cin >> t;
  for (int i = 1; i <= t; i++) {
    solve();
  }
}

K-Scheming Furry_2023牛客暑期多校训练营8 (nowcoder.com)

思路

很容易发现其实在n,m都不等于2时答案只可能是fox和平局,然后再分别讨论n,m分别为2和同时为2的时候答案即可。

代码

#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define fi first
#define sc second

using namespace std;
const int INF = 0x3f3f3f3f3f3f3f3f;
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
typedef pair<int, int> PII;
int n, m;
int a[N];

int mp[500][500];
int tmp[500][500];
void solve() {
	cin >> n >> m;
	bool ok = 0;
	for (int i = 1; i <= n; i++) {
		int l = INF, r = -INF;
		for (int j = 1; j <= m; j++) {
			cin >> mp[i][j];
			l = min(mp[i][j], l);
			r = max(mp[i][j], r);
		}
		if (r - l + 1 != m) ok = 1;
	}
	
	if (!ok) {
		if (n == 2 || m == 2) {
			if (n == 2 && m == 2) {
				// cout << "***";
				for (int i = 1; i <= n; i++) {
					int l = INF;
					for (int j = 1; j <= m; j++) {
						l = min(l, mp[i][j]);
					}
					for (int j = 1; j <= m; j++) {
						tmp[i][j] = mp[i][j] - l;
					}
				}
				
				for (int i = 1; i <= m; i++) {
					for (int j = 2; j <= n; j++) {
						if (tmp[j][i] != tmp[1][i]) {
							cout << "NSFW\n";
							return;
						}
					}
				}
				
				// 2 1
				// 4 3
				if (mp[1][1] == 2 && mp[1][2] == 1 && mp[2][1] == 4 && mp[2][2] == 3) {
					cout << "FOX\n";
					return;
				}
				
				// 3 4
				// 1 2
				if (mp[1][1] == 3 && mp[1][2] == 4 && mp[2][1] == 1 && mp[2][2] == 2) {
					cout << "FOX\n";
					return;
				}
				
				// 4 3
				// 2 1
				if (mp[1][1] == 4 && mp[1][2] == 3 && mp[2][1] == 2 && mp[2][2] == 1) {
					cout << "CAT\n";
					return;
				}
			} else {
				if (n == 2) {
					for (int i = 1; i <= n; i++) {
						int l = INF;
						for (int j = 1; j <= m; j++) {
							l = min(l, mp[i][j]);
						}
						for (int j = 1; j <= m; j++) {
							tmp[i][j] = mp[i][j] - l;
						}
					}
					
					for (int i = 1; i <= m; i++) {
						for (int j = 2; j <= n; j++) {
							if (tmp[j][i] != tmp[1][i]) {
								cout << "NSFW\n";
								return;
							}
						}
					}
                    if(is_sorted(tmp[1]+1,tmp[1]+m+1)) {
                        cout<<"FOX\n";
                        return;
                    }
					
					int cnt = 0;
					for (int j = 1; j <= m; j++) {
						for (int k = j + 1; k <= m; k++) {
							if (mp[1][j] > mp[1][k]) cnt++;
						}
					}
					
					if (mp[1][1] > mp[2][1]) cnt++;
					//cout<<cnt<<"\n";
					if (cnt % 2 == 0)
						cout << "CAT\n";
					else
						cout << "NSFW\n";
					return;
				} else if (m == 2) {
					for (int i = 1; i <= n; i++) {
						int l = INF;
						for (int j = 1; j <= m; j++) {
							l = min(l, mp[i][j]);
						}
						for (int j = 1; j <= m; j++) {
							tmp[i][j] = mp[i][j] - l;
						}
					}
					
					for (int i = 1; i <= m; i++) {
						for (int j = 2; j <= n; j++) {
							if (tmp[j][i] != tmp[1][i]) {
								cout << "NSFW\n";
								return;
							}
						}
					}
					
					int cnt = 0;
					for (int j = 1; j <= n; j++) {
						for (int k = j + 1; k <= n; k++) {
							if (mp[j][1] > mp[k][1]) cnt++;
						}
					}
					
					if (mp[1][1] > mp[1][2]) cnt++;
					
					if (cnt % 2 == 1)
						cout << "FOX\n";
					else
						cout << "NSFW\n";
					return;
				}
			}
		} else {
			for (int i = 1; i <= n; i++) {
				int l = INF;
				for (int j = 1; j <= m; j++) {
					l = min(l, mp[i][j]);
				}
				for (int j = 1; j <= m; j++) {
					tmp[i][j] = mp[i][j] - l;
				}
			}
			
			for (int i = 1; i <= m; i++) {
				for (int j = 2; j <= n; j++) {
					if (tmp[j][i] != tmp[1][i]) {
						cout << "NSFW\n";
						return;
					}
				}
			}
			int cnt = 0;
			
			
			if(is_sorted(mp[1]+1,mp[1]+m+1)) {
				for (int i = 1; i <= n; i++) {
					if (mp[i][1] != 1 + (i - 1)*m) cnt++;
				}
				if (cnt == 2) {
					cout << "FOX\n";
					return;
				} else {
					cout << "NSFW\n";
					return;
				}
			} else {
				cout << "NSFW\n";
				return;
			}
		}
	} else {
		cout << "NSFW\n";
		return;
	}
}

signed main() {
	IOS;
	int t = 1;
	cin >> t;
	for (int i = 1; i <= t; i++) {
		solve();
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
2023牛客史上最全MySQL大厂常问面试题合集,是一份总结了许多MySQL常见面试问题的资料。在MySQL作为关系型数据库中的重要一员,业界使用率极高,成为了大厂面试的必考点之一。对于面试者来说,掌握MySQL相关知识无疑是非常重要的。 面对这样一份面试题合集,我们需要掌握MySQL的基本架构、性能优化、存储引擎等方面的知识。首先,我们需要了解MySQL的基本架构,即MySQL架构的三层结构,包括连接处理层、查询处理层和存储引擎层。此外,对于查询语句的优化,我们需要了解索引的使用、查询语句的执行流程等概念,并且掌握MySQL自带的调优工具。 在MySQL性能优化方面,我们可以从硬件、操作系统、MySQL本身以及SQL语句的角度入手。例如,可以从MySQL参数配置、SQL执行计划、SQL调优等方面解决性能问题。同时,由于存储引擎对于MySQL的性能非常关键,我们也需要了解InnoDB和MyISAM这两种主流存储引擎的特点与优缺点,及其在实际应用中的使用情况。 总之,掌握MySQL的基本架构、性能优化、存储引擎等知识是应聘MySQL岗位时不可或缺的必备技能。面对这份全牛客史上最全MySQL大厂常问面试题合集,需要认真学习、反复练习,并对自己的掌握情况进行不断的总结与提高。只有做到这些,才能在面试中展现出自己的实力,获得满意的工作机会。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值