0%

Code

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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
ID: wcr19961
PROG: msquare
LANG: C++11
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;

typedef long long LL;
const int maxn = 10;
const int maxm = 100330;
const int A[maxn] = {1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880};
int len[maxm], fa[maxm];
char p[maxm], s[maxm];
bool vis[maxm];
struct node {
int a[8], st;

node trans(int t) {
node k = *this;
if (t == 0) {
for (int i = 0; i < 4; ++i) {
swap(k.a[i], k.a[8 - i - 1]);
}
} else if (t == 1) {
for (int i = 3; i > 0; --i) {
swap(k.a[i], k.a[i - 1]);
swap(k.a[8 - i - 1], k.a[8 - i]);
}
} else {
swap(k.a[5], k.a[6]);
swap(k.a[2], k.a[5]);
swap(k.a[1], k.a[2]);
}
k.cantor();
return k;
}

int cantor() {
st = 0;
for (int i = 0; i < 8; ++i) {
int cnt = 0;
for (int j = i + 1; j < 8; ++j) {
if (a[i] > a[j]) {
++cnt;
}
}
st += cnt * A[7 - i];
}
return st;
}
} a;

int main() {
freopen("msquare.in", "r", stdin);
freopen("msquare.out", "w", stdout);
for (int i = 0; i < 8; ++i) {
scanf("%d", &a.a[i]);
}
int aim = a.cantor();
for (int i = 0; i < 8; ++i) {
a.a[i] = i + 1;
}
vis[a.cantor()] = true;
fa[a.st] = -1, len[a.st] = 0;
queue<node> q;
q.push(a);
while (!q.empty()) {
node k = q.front();
q.pop();
if (k.st == aim) {
printf("%d\n", len[aim]);
int cnt = 0;
while (fa[aim] != -1) {
s[cnt++] = p[aim];
aim = fa[aim];
}
for (int i = 0; i < cnt; ++i) {
putchar(s[cnt - i - 1]);
if (i % 60 == 59) {
puts("");
}
}
if (cnt == 0 || cnt % 60 != 0) {
puts("");
}
return 0;
}
for (int i = 0; i < 3; ++i) {
node x = k.trans(i);
if (!vis[x.st]) {
vis[x.st] = true;
len[x.st] = len[k.st] + 1;
fa[x.st] = k.st;
p[x.st] = i + 'A';
q.push(x);
}
}
}
return 0;
}

Code

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
45
46
47
48
49
50
51
52
53
54
55
/*
ID: wcr19961
PROG: ratios
LANG: C++11
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

typedef long long LL;
const int inf = 0x3f3f3f3f;
const int maxn = 5;
int a[maxn], b[maxn], c[maxn];

int main() {
freopen("ratios.in", "r", stdin);
freopen("ratios.out", "w", stdout);
int x, y, z;
scanf("%d%d%d", &x, &y, &z);
for (int i = 0; i < 3; ++i) {
scanf("%d%d%d", &a[i], &b[i], &c[i]);
}
int ansi, ansj, ansk, ans = 0x3f3f3f3f;
for (int i = 0; i < 100; ++i) {
for (int j = 0; j < 100; ++j) {
for (int k = 0; k < 100; ++k) {
if (i + j + k == 0) {
continue;
}
int xx = i * a[0] + j * a[1] + k * a[2];
int yy = i * b[0] + j * b[1] + k * b[2];
int zz = i * c[0] + j * c[1] + k * c[2];
if ((x == 0 && xx != 0) || (y == 0 && yy != 0) || (z == 0 && zz != 0)) {
continue;
}
if ((x == 0 || xx % x == 0) && (y == 0 || yy % y == 0) && (z == 0 || zz % z == 0)) {
int tmp = x != 0 ? xx / x : (y != 0 ? yy / y : zz / z);
if (tmp < ans && (x == 0 || xx / x == tmp) && (y == 0 || yy / y == tmp) && (z == 0 || zz / z == tmp)) {
ans = tmp;
ansi = i;
ansj = j;
ansk = k;
}
}
}
}
}
if (ans == inf) {
puts("NONE");
} else {
printf("%d %d %d %d\n", ansi, ansj, ansk, ans);
}
return 0;
}

Code

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
45
46
47
48
49
50
51
52
53
54
55
/*
ID: wcr19961
PROG: spin
LANG: C++11
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

typedef long long LL;
const int maxn = 7;
const int maxm = 365;
int ok[maxm];
int v[maxn], num[maxn];
int p[maxn][maxn], w[maxn][maxn];

bool check(int x) {
memset(ok, 0, sizeof ok);
for (int i = 1; i <= 5; ++i) {
int px = x * v[i];
for (int j = 0; j < num[i]; ++j) {
for (int k = 0; k <= w[i][j]; ++k) {
if (ok[(px + p[i][j] + k) % 360] == i - 1) {
++ok[(px + p[i][j] + k) % 360];
}
}
}
}
for (int i = 0; i < 360; ++i) {
if (ok[i] == 5) {
return true;
}
}
return false;
}

int main() {
freopen("spin.in", "r", stdin);
freopen("spin.out", "w", stdout);
for (int i = 1; i <= 5; ++i) {
scanf("%d%d", &v[i], &num[i]);
for (int j = 0; j < num[i]; ++j) {
scanf("%d%d", &p[i][j], &w[i][j]);
}
}
for (int i = 0; i < 360; ++i) {
if (check(i)) {
printf("%d\n", i);
return 0;
}
}
puts("none");
return 0;
}

Code

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
/*
ID: wcr19961
PROG: kimbits
LANG: C++11
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

typedef long long LL;
const int maxn = 35;
LL c[maxn][maxn];

int main() {
freopen("kimbits.in", "r", stdin);
freopen("kimbits.out", "w", stdout);
for (int i = 0; i < maxn; ++i) {
c[i][0] = 1;
for (int j = 1; j <= i; ++j) {
c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
}
}
for (int i = 0; i < maxn; ++i) {
for (int j = 1; j < maxn; ++j) {
c[i][j] += c[i][j - 1];
}
}
int n, l;
LL x;
scanf("%d%d%lld", &n, &l, &x);
for (int i = 0; i < n; ++i) {
if (x > c[n - i - 1][l]) {
x -= c[n - i - 1][l];
--l;
putchar('1');
} else {
putchar('0');
}
}
puts("");
return 0;
}

Code

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
/*
ID: wcr19961
PROG: fact4
LANG: C++11
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int main() {
freopen("fact4.in", "r", stdin);
freopen("fact4.out", "w", stdout);
int n, ans = 1;
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
ans *= i;
while (ans % 10 == 0) {
ans /= 10;
}
ans %= 100000;
}
printf("%d\n", ans % 10);
return 0;
}

Code

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
/*
ID: wcr19961
PROG: stamps
LANG: C++11
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

typedef long long LL;
const int inf = 0x3f3f3f3f;
const int maxn = 2000010;
int dp[maxn];

int main() {
freopen("stamps.in", "r", stdin);
freopen("stamps.out", "w", stdout);
int k, n, x;
scanf("%d%d", &k, &n);
memset(dp, 0x3f, sizeof dp);
dp[0] = 0;
for (int i = 1; i <= n; ++i) {
scanf("%d", &x);
for (int j = x; j < maxn; ++j) {
if (dp[j - x] < k) {
dp[j] = min(dp[j], dp[j - x] + 1);
}
}
}
int ans = 0;
while (dp[ans + 1] != inf) {
++ans;
}
printf("%d\n", ans);
return 0;
}

Code

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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
ID: wcr19961
PROG: contact
LANG: C++11
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
using namespace std;

typedef long long LL;
const int maxn = 85;
int cnt[14][(1 << 12) + 10];
string s;
char tmp[maxn];

struct node {
int num, len, x;
bool operator < (const node& rhs) const {
if (num != rhs.num) {
return num > rhs.num;
}
return len < rhs.len || (len == rhs.len && x < rhs.x);
}
void print() {
char s[14];
int x = this -> x;
s[len] = 0;
for (int i = 0; i < len; ++i) {
s[len - i - 1] = (x & 1) ? '1' : '0';
x >>= 1;
}
printf("%s", s);
}
} a[50010];

int main() {
freopen("contact.in", "r", stdin);
freopen("contact.out", "w", stdout);
int A, B, n;
scanf("%d%d%d", &A, &B, &n);
while (~scanf("%s", tmp)) {
s += tmp;
}
for (int i = 0; i < int(s.length()); ++i) {
int x = 0;
for (int j = 0; j < B && i + j < int(s.length()); ++j) {
x <<= 1;
if (s[i + j] == '1') {
++x;
}
++cnt[j + 1][x];
}
}
int num = 0;
for (int i = A; i <= B; ++i) {
int ub = 1 << i;
for (int j = 0; j < ub; ++j) {
if (cnt[i][j] > 0) {
a[num].num = cnt[i][j];
a[num].len = i;
a[num].x = j;
++num;
}
}
}
sort(a, a + num);
int p = 0;
while (n-- && p < num) {
int x = a[p].num, y = 0;
printf("%d\n", x);
bool flag = true;
while (p < num && a[p].num == x) {
if (flag) {
flag = false;
} else {
putchar(' ');
}
a[p].print();
if (++y == 6) {
y = 0;
puts("");
flag = true;
}
++p;
}
if (y) {
puts("");
}
}
return 0;
}

Code

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
45
46
47
48
49
/*
ID: wcr19961
PROG: humble
LANG: C++11
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
using namespace std;

typedef long long LL;
const int maxn = 110;
int a[maxn];

int main() {
freopen("humble.in", "r", stdin);
freopen("humble.out", "w", stdout);
int k, n;
scanf("%d%d", &k, &n);
for (int i = 0; i < k; ++i) {
scanf("%d", &a[i]);
}
set<LL> s;
s.insert(1);
//++n;
for (int i = 0; ; ++i) {
LL x = *s.begin();
s.erase(s.begin());
if (i == n) {
printf("%lld\n", x);
return 0;
}
for (int j = 0; j < k; ++j) {
LL tmp = x * a[j];
if (!s.count(tmp)) {
if (s.size() < n - i) {
s.insert(tmp);
} else if (s.size() == n - i && *s.rbegin() > tmp) {
s.erase((++s.rbegin()).base());
s.insert(tmp);
}
}
}
}
return 0;
}

Code

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
/*
ID: wcr19961
PROG: inflate
LANG: C++11
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <set>
using namespace std;

const int maxn = 10010;
int dp[maxn];


int main() {
freopen("inflate.in", "r", stdin);
freopen("inflate.out", "w", stdout);
int m, n;
scanf("%d%d", &m, &n);
for (int i = 0; i < n; ++i) {
int w, c;
scanf("%d%d", &w, &c);
for (int j = c; j <= m; ++j) {
dp[j] = max(dp[j], dp[j - c] + w);
}
}
int ans = 0;
for (int i = 0; i <= m; ++i) {
ans = max(ans, dp[i]);
}
printf("%d\n", ans);
return 0;
}

Code

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
45
46
47
/*
ID: wcr19961
PROG: agrinet
LANG: C++11
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <set>
using namespace std;

const int inf = 0x3f3f3f3f;
const int maxn = 110;
int d[maxn][maxn], len[maxn], ans;
bool vis[maxn];

int main() {
freopen("agrinet.in", "r", stdin);
freopen("agrinet.out", "w", stdout);
int n;
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
len[i] = inf;
for (int j = 1; j <= n; ++j) {
scanf("%d", &d[i][j]);
}
}
int u = 1, cnt = n - 1;
while (cnt--) {
vis[u] = true;
int v = -1, best = inf;
for (int i = 1; i <= n; ++i) {
if (!vis[i]) {
len[i] = min(len[i], d[u][i]);
if (len[i] < best) {
best = len[i];
v = i;
}
}
}
ans += best;
u = v;
}
printf("%d\n", ans);
return 0;
}