第32次CSP认证(持续更新)
第32次CSP认证(持续更新)
仓库规划
思路
数据范围较小,直接暴力判断
对每一个仓库,遍历其他每一个仓库,看看哪个是它的上级,如果都没有就输出\(0\)
时间复杂度: \(O(n^2m)\)
代码
神奇的代码
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using i64 = long long;
using u64 = unsigned long long;
struct custom_hash
{
static uint64_t splitmix64(uint64_t x)
{
x ^= x << 13;
x ^= x >> 7;
x ^= x << 17;
return x;
}
size_t operator () (uint64_t x) const
{
static const uint64_t FIXED_RANDOM = std::chrono::steady_clock::now().time_since_epoch().count(); // 时间戳
return splitmix64(x + FIXED_RANDOM);
}
};
int nums[1010][12];
void solve()
{
int n = 0, m = 0;
std::cin >> n >> m;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
std::cin >> nums[i][j];
}
}
for (int i = 1; i <= n; i++)
{
bool flag = false;
for (int j = 1; j <= n; j++)
{
bool f = true;
if(i == j) continue;
for (int k = 1; k <= m; k++)
{
if (nums[j][k] <= nums[i][k])
{
f = false;
break;
}
}
if (f)
{
std::cout << j << endl;
flag = true;
break;
}
}
if (!flag)
{
std::cout << 0 << endl;
}
}
}
signed main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr); std::cout.tie(nullptr);
int t = 1;
//std::cin >> t;
while(t--)
{
solve();
}
return 0;
}
因子化简
思路
注意到\(2 \leq k \leq 10\),而\((10^5)^2 = 10^{10}\),那么\(10^5\)之外的素数都不用考虑了,一定不能保留。
那么我们可以先把\(1o^5\)以内的素数预处理出来,一个一个判断就好
\(10^5\)以内的素数不超过\(10^4\)个,询问不超过\(10\)个,判断一个数不超过\(40\)次,最大时间复杂度\(O(4 * 10^6)\)
代码
神奇的代码
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using i64 = long long;
using u64 = unsigned long long;
const int maxn = 1e5 + 2;
struct custom_hash
{
static uint64_t splitmix64(uint64_t x)
{
x ^= x << 13;
x ^= x >> 7;
x ^= x << 17;
return x;
}
size_t operator () (uint64_t x) const
{
static const uint64_t FIXED_RANDOM = std::chrono::steady_clock::now().time_since_epoch().count(); // 时间戳
return splitmix64(x + FIXED_RANDOM);
}
};
inline int read()
{
int x = 0, flag = 1;
char ch = getchar();
while(ch < '0' || ch > '9')
{
if(ch == '-')
{
flag = -1;
}
ch = getchar();
}
while(ch <= '9' && ch >= '0')
{
x = x * 10 + ch - '0';
ch = getchar();
}
return x * flag;
}
int prime[maxn];
int cnt = 0;
int v[maxn]; // 存的是最小质因子
int power(int y, int x)
{
int res = 1;
while(x)
{
if (x & 1)
{
res *= y;
}
y *= y;
x >>= 1;
}
return res;
}
void prime_filter() // 欧拉筛
{
for (int i = 2; i <= maxn; i++)
{
if (v[i] == 0)
{
prime[++cnt] = i;
v[i] = i;
}
for (int j = 1; j <= cnt; j++)
{
if (prime[j] > v[i] || i * prime[j] > maxn) break;
v[i * prime[j]] = prime[j];
}
}
}
bool check(int pos, int k, int n)
{
return power(prime[pos], k) <= n;
}
void solve()
{
int n = 0, k = 0;
n = read(), k = read();
int ans = 1;
for (int i = 1; i <= cnt; i++)
{
if (n < prime[i]) break;
int cnt = 0;
while(n % prime[i] == 0)
{
cnt++;
n /= prime[i];
}
if (cnt >= k)
{
ans *= power(prime[i], cnt);
}
}
std::cout << ans << endl;
}
signed main()
{
// std::ios::sync_with_stdio(false);
// std::cin.tie(nullptr); std::cout.tie(nullptr);
prime_filter();
int t = 1;
t = read();
while(t--)
{
solve();
}
return 0;
}