蓝桥杯每日一题2023.10.28

题目描述

递增三元组 - 蓝桥云课 (lanqiao.cn)

题目分析

60分解法:

直接暴力循环每一个数进行比较

cpp 复制代码
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
typedef long long ll;
ll n, a[N], b[N], c[N], ans;
int 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 ++)cin >> c[i];
	for(int i = 1; i <= n; i ++)
	{
		for(int j = 1; j <= n; j ++)
		{
			for(int k = 1; k <= n; k ++)
			{
				if(a[i] < b[j] && b[j] < c[k])ans ++;
			}
		}
	}
	cout << ans;
	return 0;
}

满分解法:

由于ABC的值是完全独立的所以可以使用乘法原理

由B作为一个判断点,看有多少个A符合要求,再看有多少个C符合要求,最后的答案则为两部分相乘的结果

cpp 复制代码
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
ll n, a[N], b[N], c[N], s[N], cnt[N];
ll sa[N];//sa[i]表示在a[]中有多少个数小于b[i] 
ll sc[N];//sc[i]表示在c[]中有多少个数大于b[i]
int main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n;
	for(int i = 1; i <= n; i ++)cin >> a[i], a[i] ++;
	for(int i = 1; i <= n; i ++)cin >> b[i], b[i] ++;
	for(int i = 1; i <= n; i ++)cin >> c[i], c[i] ++;
	//求sa[] 
	for(int i = 1; i <= n; i ++)cnt[a[i]] ++;
	for(int i = 1; i <= N; i ++)s[i] = s[i - 1] + cnt[i];
	for(int i = 1; i <= n; i ++)sa[i] = s[b[i] - 1];
	//求sc[] 
	memset(cnt, 0, sizeof cnt);
	memset(s, 0, sizeof s);
	for(int i = 1; i <= n; i ++)cnt[c[i]] ++;
	for(int i = 1; i <= N; i ++)s[i] = s[i - 1] + cnt[i];
	for(int i = 1; i <= n; i ++)sc[i] = s[N] - s[b[i]];
	//枚举每个b[i]
	ll ans = 0;
	for(int i = 1; i <= n; i ++)ans += sa[i] * sc[i];
	cout << ans;
	return 0;
}
相关推荐
元亓亓亓2 天前
LeetCode热题100--105. 从前序与中序遍历序列构造二叉树--中等
算法·leetcode·职场和发展
测试老哥2 天前
Selenium 使用指南
自动化测试·软件测试·python·selenium·测试工具·职场和发展·测试用例
仙俊红2 天前
LeetCode每日一题,20250914
算法·leetcode·职场和发展
前端小超超3 天前
capacitor配置ios应用图标不同尺寸
ios·蓝桥杯·cocoa
睡不醒的kun3 天前
leetcode算法刷题的第三十四天
数据结构·c++·算法·leetcode·职场和发展·贪心算法·动态规划
吃着火锅x唱着歌3 天前
LeetCode 1446.连续字符
算法·leetcode·职场和发展
武子康4 天前
AI-调查研究-76-具身智能 当机器人走进生活:具身智能对就业与社会结构的深远影响
人工智能·程序人生·ai·职场和发展·机器人·生活·具身智能
Nan_Shu_6144 天前
Web前端面试题(1)
前端·面试·职场和发展
YuTaoShao4 天前
【LeetCode 每日一题】3000. 对角线最长的矩形的面积
算法·leetcode·职场和发展
007php0074 天前
Redis高级面试题解析:深入理解Redis的工作原理与优化策略
java·开发语言·redis·nginx·缓存·面试·职场和发展