Skip to content

Commit 5e84d23

Browse files
committed
update
1 parent 55bf3c4 commit 5e84d23

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Time: 265 ms
2+
// Memory: 1200 KB
3+
// Debug 2h 多...
4+
// T:O(n), S:O(1)
5+
//
6+
import java.util.Scanner;
7+
8+
public class Codeforces_0371C_Hamburgers {
9+
public static void main(String[] args) {
10+
Scanner sc = new Scanner(System.in);
11+
String str = sc.next();
12+
int na = sc.nextInt(), nb = sc.nextInt(), nc = sc.nextInt();
13+
int pa = sc.nextInt(), pb = sc.nextInt(), pc = sc.nextInt();
14+
int ca = 0, cb = 0, cc = 0;
15+
long ret = 0, r = sc.nextLong();
16+
for (char c : str.toCharArray()) {
17+
if (c == 'B') {
18+
ca++;
19+
} else if (c == 'S') {
20+
cb++;
21+
} else {
22+
cc++;
23+
}
24+
}
25+
int min1 = Math.min(Math.min(ca == 0 ? 0 : (na / ca), cb == 0 ? 0 : (nb / cb)), cc == 0 ? 0 : (nc / cc));
26+
ret += min1;
27+
na -= min1 * ca;
28+
nb -= min1 * cb;
29+
nc -= min1 * cc;
30+
31+
while ((ca > 0 && na > 0) || (cb > 0 && nb > 0) || (cc > 0 && nc > 0)) {
32+
int onePkg = 0;
33+
if (ca > 0) {
34+
if (na >= ca) {
35+
na -= ca;
36+
} else {
37+
onePkg += (ca - na) * pa;
38+
na = 0;
39+
}
40+
}
41+
if (cb > 0) {
42+
if (nb > cb) {
43+
nb -= cb;
44+
} else {
45+
onePkg += (cb - nb) * pb;
46+
nb = 0;
47+
}
48+
}
49+
if (cc > 0) {
50+
if (nc > cc) {
51+
nc -= cc;
52+
} else {
53+
onePkg += (cc - nc) * pc;
54+
nc = 0;
55+
}
56+
}
57+
58+
if (r >= onePkg) {
59+
r -= onePkg;
60+
ret++;
61+
} else {
62+
break;
63+
}
64+
}
65+
if (r > 0) {
66+
int onePkg = ca * pa + cb * pb + cc * pc;
67+
ret += r / onePkg;
68+
}
69+
70+
System.out.println(ret);
71+
}
72+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Time: 327 ms
2+
// Memory: 1600 KB
3+
// Math: 注意到条件2,为了让所有数 & 和为0,同时又使总和最大,那么只需使得 n 个数的
4+
// 每个二进制位(总共 k 个位),均为 (n-1)个 1 和 1 个 0,这样数组变化个数为 n^k.
5+
// T:O(sum(ki)), S:O(1)
6+
//
7+
import java.util.Scanner;
8+
9+
public class Codeforces_1514B_AND_0_Sum_Big {
10+
public static void main(String[] args) {
11+
Scanner sc = new Scanner(System.in);
12+
int t = sc.nextInt();
13+
for (int i = 0; i < t; i++) {
14+
int n = sc.nextInt(), k = sc.nextInt();
15+
long ret = 1;
16+
for (int j = 0; j < k; j++) {
17+
ret = (long) ((ret * n) % (1e9 + 7));
18+
}
19+
20+
System.out.println(ret);
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)