Skip to content

Commit 03b1172

Browse files
committed
Moar
1 parent bed6cf9 commit 03b1172

File tree

8 files changed

+568
-0
lines changed

8 files changed

+568
-0
lines changed

acm.timus.ru/1501-1600/1590.java

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class Main {
5+
private FastScanner in;
6+
private PrintWriter out;
7+
8+
int lcp_length(String a, String b) {
9+
if (a.length() > b.length()) {
10+
return lcp_length(b, a);
11+
}
12+
13+
for (int i = 0; i < a.length(); i++) {
14+
if (a.charAt(i) != b.charAt(i)) {
15+
return i;
16+
}
17+
}
18+
19+
return a.length();
20+
}
21+
22+
void solve() throws IOException {
23+
String s = in.nextToken();
24+
String[] suffixes = new String[s.length()];
25+
for (int i = 0; i < s.length(); i++) {
26+
suffixes[i] = s.substring(i);
27+
}
28+
Arrays.sort(suffixes);
29+
long ans = suffixes[0].length();
30+
for (int i = 1; i < s.length(); i++) {
31+
ans += suffixes[i].length() - lcp_length(suffixes[i], suffixes[i-1]);
32+
}
33+
out.println(ans);
34+
out.flush();
35+
}
36+
37+
Main() {
38+
this.in = new FastScanner();
39+
try {
40+
this.out = new PrintWriter(System.out);
41+
} catch (Exception e) {
42+
e.printStackTrace();
43+
}
44+
}
45+
46+
public static void main(String[] args) throws IOException {
47+
new Main().solve();
48+
}
49+
50+
class FastScanner {
51+
BufferedReader br;
52+
StringTokenizer st;
53+
54+
public FastScanner() {
55+
br = new BufferedReader(new InputStreamReader(System.in));
56+
}
57+
58+
public FastScanner(String s) {
59+
try {
60+
br = new BufferedReader(new FileReader(s));
61+
} catch (FileNotFoundException e) {
62+
e.printStackTrace();
63+
}
64+
}
65+
66+
public String nextToken() {
67+
while (st == null || !st.hasMoreTokens()) {
68+
try {
69+
st = new StringTokenizer(br.readLine());
70+
} catch (IOException e) {
71+
}
72+
}
73+
return st.nextToken();
74+
}
75+
76+
public int nextInt() {
77+
return Integer.parseInt(nextToken());
78+
}
79+
80+
public long nextLong() {
81+
return Long.parseLong(nextToken());
82+
}
83+
84+
public double nextDouble() {
85+
return Double.parseDouble(nextToken());
86+
}
87+
}
88+
}

codeforces/8xx/808A.java

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
/**
5+
* Built using CHelper plug-in
6+
* Actual solution is at the top
7+
*
8+
* @author kronos
9+
*/
10+
public class Main {
11+
public static void main(String[] args) {
12+
InputStream inputStream = System.in;
13+
OutputStream outputStream = System.out;
14+
FastScanner in = new FastScanner(inputStream);
15+
PrintWriter out = new PrintWriter(outputStream);
16+
TaskA solver = new TaskA();
17+
solver.solve(1, in, out);
18+
out.close();
19+
}
20+
21+
static class TaskA {
22+
public void solve(int testNumber, FastScanner in, PrintWriter out) {
23+
int a = in.nextInt();
24+
StringBuilder s = new StringBuilder();
25+
s.append(a);
26+
char c = s.charAt(0);
27+
if (c < '9') {
28+
s.setCharAt(0, (char) ((int) c + 1));
29+
for (int i = 1; i < s.length(); i++) {
30+
s.setCharAt(i, '0');
31+
}
32+
} else {
33+
for (int i = 0; i < s.length(); i++) {
34+
s.setCharAt(i, '0');
35+
}
36+
s = new StringBuilder("1" + s.toString());
37+
}
38+
out.println(Integer.valueOf(s.toString()) - a);
39+
}
40+
41+
}
42+
43+
static class FastScanner {
44+
BufferedReader br;
45+
StringTokenizer st;
46+
47+
public FastScanner() {
48+
br = new BufferedReader(new InputStreamReader(System.in));
49+
}
50+
51+
public FastScanner(InputStream stream) {
52+
br = new BufferedReader(new InputStreamReader(stream));
53+
}
54+
55+
public FastScanner(String s) {
56+
try {
57+
br = new BufferedReader(new FileReader(s));
58+
} catch (FileNotFoundException e) {
59+
e.printStackTrace();
60+
}
61+
}
62+
63+
public String next() {
64+
while (st == null || !st.hasMoreTokens()) {
65+
try {
66+
st = new StringTokenizer(br.readLine());
67+
} catch (IOException e) {
68+
}
69+
}
70+
return st.nextToken();
71+
}
72+
73+
public int nextInt() {
74+
return Integer.parseInt(next());
75+
}
76+
77+
}
78+
}

codeforces/8xx/808B.java

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
/**
5+
* Built using CHelper plug-in
6+
* Actual solution is at the top
7+
*
8+
* @author kronos
9+
*/
10+
public class Main {
11+
public static void main(String[] args) {
12+
InputStream inputStream = System.in;
13+
OutputStream outputStream = System.out;
14+
FastScanner in = new FastScanner(inputStream);
15+
PrintWriter out = new PrintWriter(outputStream);
16+
TaskB solver = new TaskB();
17+
solver.solve(1, in, out);
18+
out.close();
19+
}
20+
21+
static class TaskB {
22+
public void solve(int testNumber, FastScanner in, PrintWriter out) {
23+
int n = in.nextInt();
24+
int k = in.nextInt();
25+
int[] a = new int[n];
26+
long sum, p = 0;
27+
int groups = n - k + 1;
28+
for (int i = 0; i < n; i++) {
29+
a[i] = in.nextInt();
30+
}
31+
32+
for (int i = 0; i < k; i++) {
33+
p += a[i];
34+
}
35+
sum = p;
36+
37+
for (int i = k; i < n; i++) {
38+
p += a[i] - a[i - k];
39+
sum += p;
40+
}
41+
42+
out.printf("%.10f", (double) sum / groups);
43+
out.flush();
44+
}
45+
46+
}
47+
48+
static class FastScanner {
49+
BufferedReader br;
50+
StringTokenizer st;
51+
52+
public FastScanner() {
53+
br = new BufferedReader(new InputStreamReader(System.in));
54+
}
55+
56+
public FastScanner(InputStream stream) {
57+
br = new BufferedReader(new InputStreamReader(stream));
58+
}
59+
60+
public FastScanner(String s) {
61+
try {
62+
br = new BufferedReader(new FileReader(s));
63+
} catch (FileNotFoundException e) {
64+
e.printStackTrace();
65+
}
66+
}
67+
68+
public String next() {
69+
while (st == null || !st.hasMoreTokens()) {
70+
try {
71+
st = new StringTokenizer(br.readLine());
72+
} catch (IOException e) {
73+
}
74+
}
75+
return st.nextToken();
76+
}
77+
78+
public int nextInt() {
79+
return Integer.parseInt(next());
80+
}
81+
82+
}
83+
}

codeforces/8xx/808C.java

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
/**
5+
* Built using CHelper plug-in
6+
* Actual solution is at the top
7+
*
8+
* @author kronos
9+
*/
10+
public class Main {
11+
public static void main(String[] args) {
12+
InputStream inputStream = System.in;
13+
OutputStream outputStream = System.out;
14+
FastScanner in = new FastScanner(inputStream);
15+
PrintWriter out = new PrintWriter(outputStream);
16+
TaskC solver = new TaskC();
17+
solver.solve(1, in, out);
18+
out.close();
19+
}
20+
21+
static class TaskC {
22+
public void solve(int testNumber, FastScanner in, PrintWriter out) {
23+
int n = in.nextInt();
24+
int w = in.nextInt();
25+
Friend[] f = new Friend[n];
26+
int sum = 0, q;
27+
for (int i = 0; i < n; i++) {
28+
f[i] = new Friend(in.nextInt(), i);
29+
sum += f[i].ans;
30+
w -= f[i].ans;
31+
}
32+
33+
if (w < 0) {
34+
out.println(-1);
35+
} else {
36+
Arrays.sort(f, new Comparator<Friend>() {
37+
38+
public int compare(final Friend left, final Friend right) {
39+
return left.a - right.a;
40+
}
41+
});
42+
43+
for (int i = n - 1; (i >= 0) && (w > 0); i--) {
44+
q = Integer.min(f[i].left(), w);
45+
f[i].ans += q;
46+
w -= q;
47+
}
48+
49+
Arrays.sort(f, new Comparator<Friend>() {
50+
51+
public int compare(final Friend left, final Friend right) {
52+
return left.i - right.i;
53+
}
54+
});
55+
56+
for (int i = 0; i < n; i++) {
57+
out.printf("%d ", f[i].ans);
58+
}
59+
}
60+
out.flush();
61+
}
62+
63+
class Friend {
64+
public int a;
65+
public int ans;
66+
public int i;
67+
68+
Friend(int a, int i) {
69+
this.a = a;
70+
this.ans = a / 2 + a % 2;
71+
this.i = i;
72+
}
73+
74+
public int left() {
75+
return a - ans;
76+
}
77+
78+
}
79+
80+
}
81+
82+
static class FastScanner {
83+
BufferedReader br;
84+
StringTokenizer st;
85+
86+
public FastScanner() {
87+
br = new BufferedReader(new InputStreamReader(System.in));
88+
}
89+
90+
public FastScanner(InputStream stream) {
91+
br = new BufferedReader(new InputStreamReader(stream));
92+
}
93+
94+
public FastScanner(String s) {
95+
try {
96+
br = new BufferedReader(new FileReader(s));
97+
} catch (FileNotFoundException e) {
98+
e.printStackTrace();
99+
}
100+
}
101+
102+
public String next() {
103+
while (st == null || !st.hasMoreTokens()) {
104+
try {
105+
st = new StringTokenizer(br.readLine());
106+
} catch (IOException e) {
107+
}
108+
}
109+
return st.nextToken();
110+
}
111+
112+
public int nextInt() {
113+
return Integer.parseInt(next());
114+
}
115+
116+
}
117+
}

0 commit comments

Comments
 (0)