大厂笔试题
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

59 lines
1.4 KiB

#include <iostream>
#include <vector>
#include <set>
#include <numeric>
#include <algorithm>
#include <cmath>
using namespace std;
// 计算一个数的质因数的最小公倍数
long long lcm(long long a, long long b) {
return a / __gcd(a, b) * b;
}
// 计算一个城堡的完美度
long long calculateCastlePerfectness(const vector<pair<int, int>>& blocks) {
long long product = 1;
for (const auto& block : blocks) {
product *= pow(block.first, block.second);
}
return product;
}
int main() {
int n;
cin >> n;
vector<long long> perfectness(n);
vector<vector<pair<int, int>>> castles(n);
for (int i = 0; i < n; ++i) {
int ti;
cin >> ti;
castles[i].resize(ti);
for (int j = 0; j < ti; ++j) {
int Pij, Cij;
cin >> Pij >> Cij;
castles[i][j] = {Pij, Cij};
}
perfectness[i] = calculateCastlePerfectness(castles[i]);
}
// 计算总完美度
set<long long> uniquePerfectness;
for (int i = 0; i < n; ++i) {
long long currentLcm = 1;
for (int j = 0; j < n; ++j) {
if (j != i) {
currentLcm = lcm(currentLcm, perfectness[j]);
}
}
uniquePerfectness.insert(currentLcm);
}
// 输出不同的总完美度的种数
cout << uniquePerfectness.size() << endl;
return 0;
}