Snuke Festival

本文介绍了一个关于如何计算可以构建的不同祭坛数量的问题。通过给定的三个数组,分别代表上部、中部和下部祭坛部件的大小,文章详细阐述了如何确保中部部件大于上部、下部部件大于中部的情况下,计算所有可能的不同组合。

题目描述

The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower.
He has N parts for each of the three categories. The size of the i-th upper part is Ai, the size of the i-th middle part is Bi, and the size of the i-th lower part is Ci.
To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar.
How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.

Constraints
1≤N≤105
1≤Ai≤109(1≤i≤N)
1≤Bi≤109(1≤i≤N)
1≤Ci≤109(1≤i≤N)
All input values are integers.

 

输入

Input is given from Standard Input in the following format:
N
A1 … AN
B1 … BN
C1 … CN

 

输出

Print the number of different altars that Ringo can build.

 

样例输入

2
1 5
2 4
3 6

 

样例输出

3

 

提示

The following three altars can be built:
Upper: 1-st part, Middle: 1-st part, Lower: 1-st part
Upper: 1-st part, Middle: 1-st part, Lower: 2-nd part
Upper: 1-st part, Middle: 2-nd part, Lower: 2-nd part

#include<math.h>
#include<algorithm>
#include <iostream>
using namespace std;
typedef long long int LL;
const int N=1e5+5;
int a[N];
int b[N];
int c[N];
int main()
{
int n;
cin>>n;
for(int i=0;i<n;i++)
	cin>>a[i];
for(int i=0;i<n;i++)
	cin>>b[i];
for(int i=0;i<n;i++)
	cin>>c[i];
sort(a,a+n);
sort(b,b+n);
sort(c,c+n);
LL j=0;//用于统计第一部分里面小于第二部分的个数
LL k=0;//用于统计第三部分里面小于第二部分的个数
LL sum=0;
for(int i=0;i<n;i++){
	while(a[j]<b[i]&&j<n){
	j++;
	}
	while(c[k]<=b[i]&&k<n){
	k++;
	}
	sum+=(j*(n-k));
}

cout<<sum<<endl;

	return 0;
}

 

### AtCoder Contest 186 题目与解答 #### A. Simple Calculator 在这个问题中,给定两个整数 \(a\) 和 \(b\) ,以及一个运算符 `+` 或 `-` 。需要计算并输出表达式的值。 ```python def simple_calculator(a, b, op): if op == '+': return a + b elif op == '-': return a - b print(simple_calculator(3, 5, '+')) # 输出:8 ``` [^1] #### B. Counting Characters 此题要求统计字符串中小写字母的数量,并按字母顺序输出每种字符及其出现次数。 ```python from collections import Counter def count_characters(s): counter = Counter([c for c in s if 'a' <= c <= 'z']) result = [] for char in range(ord('a'), ord('z') + 1): ch = chr(char) cnt = counter[ch] if cnt > 0: result.append(f"{ch} {cnt}") return "\n".join(result) print(count_characters("abcde")) ``` #### C. Grid Repainting 在一个由黑色和白色方格组成的矩形网格上执行若干次翻转操作。每次可以将任意行或列的颜色全部反转。目标是最少步数内使整个网格变为全白状态。 这个问题可以通过模拟来实现: ```cpp #include <bits/stdc++.h> using namespace std; int main() { int h, w; cin >> h >> w; vector<string> grid(h); for (auto& row : grid) cin >> row; bool all_white = true; for(const auto &row : grid){ for(auto cell : row){ if(cell != '.'){ all_white=false;break; } }if(!all_white)break; } cout << (all_white ? "0\n" : "-1\n"); } ``` #### D. Dividing Chocolate 给出一块巧克力板的尺寸,求将其分割成正方形所需的最小切割次数。 该问题可利用贪心算法解决: ```cpp long long dividing_chocolate(long long n, long long m) { long long cuts = 0; while(n % m != 0 && m % n != 0){ if(m>n)m-=n,cuts++; else n-=m,cuts++; } return max(n,m)-1 + cuts; } cout<<dividing_chocolate(5,7)<<endl; // 示例输入 ``` #### E. Traveler's Problem 旅行者计划访问多个城市,在满足特定条件的情况下寻找最短路径。 动态规划方法适用于此类优化问题: ```cpp const int MAXN=1e5+5; vector<pair<int,int>> adj[MAXN]; bool vis[MAXN]={false}; int dp[MAXN]; void dfs(int u){ vis[u]=true; for(auto &[v,w]:adj[u]){ if(!vis[v])dp[v]=min(dp[v],w+dp[u]),dfs(v); } } // 初始化和其他逻辑... for(int i=1;i<=cities;++i){ fill_n(dp+i*n,i,INT_MAX); dfs(i); } ``` #### F. Snuke Festival 涉及排列组合的问题,通常采用数学公式或者预处理阶乘的方法来进行高效计算。 对于这类题目,建议预先准备好必要的工具函数以便快速调用: ```cpp typedef unsigned long long ull; constexpr static const size_t NMAX{2*1e5}; ull fact[NMAX+1]; inline void init_factorial(){ memset(fact,0,sizeof(fact)); fact[0]=fact[1]=1; for(size_t i{};i<NMAX;++i)fact[i+1]=(fact[i]*(i+1))%MOD; } init_factorial(); // 调用初始化 ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值