CCF/CSP

因子化简

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <stdio.h>
#include <math.h>

void primeFactorization(long long n, int threshold) {
// 输出每个质因子及其幂次
long long ans = 1;
for (long long i = 2; i <= sqrt(n); i++) {
long long sum = 1;
if (n % i == 0) {
int count = 0;
while (n % i == 0) {
count++;
n /= i;
}
// printf("%lld^%d ", i, count);
if (count >= threshold)
sum = pow(i, count);
ans *= sum;
}
}
printf("%lld\n", ans);

// 如果 n 大于 1,则 n 本身就是一个质因子
// if (n > 1)
// printf("%lld^1", n);
// printf("\n");
}

int main() {
long long num;
int threshold;
int q;
scanf("%d", &q);
// printf("Enter a number: ");
for (int i = 1; i <= q; i++) {
scanf("%lld%d", &num, &threshold);
primeFactorization(num, threshold);
}

// printf("Prime factorization of %lld: ", num);

return 0;
}

仓库规划

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
using namespace std;
const int N = 1010;
int repo[N][11];

int main() {
// n仓库个数
// m位置编码维数
int n, m;
cin >> n >> m;

for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> repo[i][j];
}
}

for (int i = 1; i <= n; i++) {
int ans = 0;
for (int j = 1; j <= n; j++) {
if (j == i)
continue;

bool flag = true;

for (int k = 1; k <= m; k++) {
if (repo[j][k] <= repo[i][k]) {
flag = false;
}
}

if (flag) {
ans = j;
break;
}
}
cout << ans << endl;
}

return 0;
}

坐标变换(其二)