更新
@@ -1,48 +1,41 @@
|
||||
import java.util.Scanner;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.math.BigInteger;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
Scanner in = new Scanner(System.in);
|
||||
if (!in.hasNext()) {
|
||||
System.out.print("no");
|
||||
in.close();
|
||||
return;
|
||||
}
|
||||
int n = Integer.parseInt(in.next());
|
||||
if (n <= 0) {
|
||||
System.out.print("no");
|
||||
in.close();
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, Integer> cnt = new HashMap<>();
|
||||
Map<String, Integer> first = new HashMap<>();
|
||||
String best = null;
|
||||
int bestCount = 0;
|
||||
int bestIdx = Integer.MAX_VALUE;
|
||||
int idx = 0;
|
||||
while (idx < n && in.hasNext()) {
|
||||
String raw = in.next();
|
||||
String norm = new BigInteger(raw).toString();
|
||||
int c = cnt.getOrDefault(norm, 0) + 1;
|
||||
cnt.put(norm, c);
|
||||
if (!first.containsKey(norm))
|
||||
first.put(norm, idx);
|
||||
int fi = first.get(norm);
|
||||
if (best == null || c > bestCount || (c == bestCount && fi < bestIdx)) {
|
||||
best = norm;
|
||||
bestCount = c;
|
||||
bestIdx = fi;
|
||||
int n = in.nextInt();
|
||||
int[] mention = new int[101];
|
||||
boolean[][] by = new boolean[101][101];
|
||||
for (int i = 0; i < n; i++) {
|
||||
int sender = in.nextInt();
|
||||
int k = in.nextInt();
|
||||
for (int j = 0; j < k; j++) {
|
||||
int id = in.nextInt();
|
||||
if (id >= 0 && id <= 100) {
|
||||
mention[id]++;
|
||||
if (sender >= 0 && sender <= 100) by[id][sender] = true;
|
||||
}
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
if (best == null)
|
||||
System.out.print("no");
|
||||
else
|
||||
System.out.print(best);
|
||||
int bestId = 0;
|
||||
int bestCount = -1;
|
||||
for (int id = 0; id <= 100; id++) {
|
||||
if (mention[id] > bestCount) {
|
||||
bestCount = mention[id];
|
||||
bestId = id;
|
||||
}
|
||||
}
|
||||
System.out.println(bestId);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
boolean first = true;
|
||||
for (int s = 0; s <= 100; s++) {
|
||||
if (by[bestId][s]) {
|
||||
if (!first) sb.append(' ');
|
||||
sb.append(s);
|
||||
first = false;
|
||||
}
|
||||
}
|
||||
System.out.println(sb.toString());
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
Scanner in = new Scanner(System.in);
|
||||
String s = in.nextLine().trim();
|
||||
String[] parts = s.split("-");
|
||||
int y = Integer.parseInt(parts[0]);
|
||||
int m = Integer.parseInt(parts[1]);
|
||||
int d = Integer.parseInt(parts[2]);
|
||||
int[] days = {0,31,28,31,30,31,30,31,31,30,31,30,31};
|
||||
boolean leap = (y % 4 == 0 && y % 100 != 0) || (y % 400 == 0);
|
||||
if (leap) days[2] = 29;
|
||||
d++;
|
||||
if (d > days[m]) {
|
||||
d = 1;
|
||||
m++;
|
||||
if (m > 12) {
|
||||
m = 1;
|
||||
y++;
|
||||
}
|
||||
}
|
||||
System.out.printf("%04d-%02d-%02d", y, m, d);
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 2.3 MiB |
@@ -0,0 +1,41 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
Scanner in = new Scanner(System.in);
|
||||
int n = in.nextInt();
|
||||
int[] mention = new int[101];
|
||||
boolean[][] by = new boolean[101][101];
|
||||
for (int i = 0; i < n; i++) {
|
||||
int sender = in.nextInt();
|
||||
int k = in.nextInt();
|
||||
for (int j = 0; j < k; j++) {
|
||||
int id = in.nextInt();
|
||||
if (id >= 0 && id <= 100) {
|
||||
mention[id]++;
|
||||
if (sender >= 0 && sender <= 100) by[id][sender] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
int bestId = 0;
|
||||
int bestCount = -1;
|
||||
for (int id = 0; id <= 100; id++) {
|
||||
if (mention[id] > bestCount) {
|
||||
bestCount = mention[id];
|
||||
bestId = id;
|
||||
}
|
||||
}
|
||||
System.out.println(bestId);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
boolean first = true;
|
||||
for (int s = 0; s <= 100; s++) {
|
||||
if (by[bestId][s]) {
|
||||
if (!first) sb.append(' ');
|
||||
sb.append(s);
|
||||
first = false;
|
||||
}
|
||||
}
|
||||
System.out.println(sb.toString());
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 2.3 MiB |
@@ -0,0 +1,59 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
Scanner in = new Scanner(System.in);
|
||||
int n = in.nextInt();
|
||||
long[] w = new long[n];
|
||||
long[] dist = new long[n];
|
||||
for (int i = 0; i < n; i++) {
|
||||
w[i] = in.nextLong();
|
||||
dist[i] = in.nextLong();
|
||||
}
|
||||
long[] pos = new long[n];
|
||||
long L = 0;
|
||||
for (int i = 0; i < n; i++)
|
||||
L += dist[i];
|
||||
for (int i = 1; i < n; i++)
|
||||
pos[i] = pos[i - 1] + dist[i - 1];
|
||||
int m = 2 * n;
|
||||
long[] pos2 = new long[m];
|
||||
long[] w2 = new long[m];
|
||||
for (int i = 0; i < m; i++) {
|
||||
int j = i % n;
|
||||
pos2[i] = pos[j] + (long) (i / n) * L;
|
||||
w2[i] = w[j];
|
||||
}
|
||||
long[] preW = new long[m + 1];
|
||||
long[] preWP = new long[m + 1];
|
||||
for (int i = 0; i < m; i++) {
|
||||
preW[i + 1] = preW[i] + w2[i];
|
||||
preWP[i + 1] = preWP[i] + w2[i] * pos2[i];
|
||||
}
|
||||
int r = 0;
|
||||
long bestCost = Long.MAX_VALUE;
|
||||
int bestIdx = 0;
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (r < i)
|
||||
r = i;
|
||||
while (r + 1 < i + n && pos2[r + 1] - pos2[i] <= L / 2)
|
||||
r++;
|
||||
long sumWcw = preW[r + 1] - preW[i];
|
||||
long sumWPcw = preWP[r + 1] - preWP[i];
|
||||
long sumWtot = preW[i + n] - preW[i];
|
||||
long sumWPtot = preWP[i + n] - preWP[i];
|
||||
long sumWccw = sumWtot - sumWcw;
|
||||
long sumWPccw = sumWPtot - sumWPcw;
|
||||
long posi = pos2[i];
|
||||
long costCW = sumWPcw - posi * sumWcw;
|
||||
long costCCW = sumWccw * L + posi * sumWccw - sumWPccw;
|
||||
long cost = costCW + costCCW;
|
||||
if (cost < bestCost || (cost == bestCost && i < bestIdx)) {
|
||||
bestCost = cost;
|
||||
bestIdx = i;
|
||||
}
|
||||
}
|
||||
System.out.println(bestIdx + "," + bestCost);
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class P2857 {
|
||||
public static void main(String[] args) {
|
||||
Scanner in = new Scanner(System.in);
|
||||
int n = in.nextInt();
|
||||
int[] mention = new int[101];
|
||||
boolean[][] by = new boolean[101][101];
|
||||
for (int i = 0; i < n; i++) {
|
||||
int sender = in.nextInt();
|
||||
int k = in.nextInt();
|
||||
for (int j = 0; j < k; j++) {
|
||||
int id = in.nextInt();
|
||||
if (id >= 0 && id <= 100) {
|
||||
mention[id]++;
|
||||
if (sender >= 0 && sender <= 100) by[id][sender] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
int bestId = 0;
|
||||
int bestCount = -1;
|
||||
for (int id = 0; id <= 100; id++) {
|
||||
if (mention[id] > bestCount) {
|
||||
bestCount = mention[id];
|
||||
bestId = id;
|
||||
}
|
||||
}
|
||||
System.out.println(bestId);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
boolean first = true;
|
||||
for (int s = 0; s <= 100; s++) {
|
||||
if (by[bestId][s]) {
|
||||
if (!first) sb.append(' ');
|
||||
sb.append(s);
|
||||
first = false;
|
||||
}
|
||||
}
|
||||
System.out.println(sb.toString());
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 2.4 MiB |
@@ -0,0 +1,17 @@
|
||||
import java.util.*;
|
||||
|
||||
public class P2840 {
|
||||
public static void main(String[] args) {
|
||||
Scanner in = new Scanner(System.in);
|
||||
List<Integer> nums = new ArrayList<>();
|
||||
while (in.hasNextInt()) nums.add(in.nextInt());
|
||||
Collections.sort(nums);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < nums.size(); i++) {
|
||||
if (i > 0) sb.append(' ');
|
||||
sb.append(nums.get(i));
|
||||
}
|
||||
System.out.println(sb.toString());
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 2.4 MiB |
@@ -0,0 +1,25 @@
|
||||
import java.util.*;
|
||||
|
||||
public class P1098 {
|
||||
public static void main(String[] args) {
|
||||
Scanner in = new Scanner(System.in);
|
||||
List<Integer> a = new ArrayList<>();
|
||||
while (in.hasNextInt()) a.add(in.nextInt());
|
||||
StringBuilder first = new StringBuilder();
|
||||
StringBuilder second = new StringBuilder();
|
||||
boolean f = true;
|
||||
for (int i = 0; i < a.size(); i++) {
|
||||
if ((i & 1) == 0) {
|
||||
if (!f) first.append(' ');
|
||||
first.append(a.get(i));
|
||||
f = false;
|
||||
} else {
|
||||
if (second.length() > 0) second.append(' ');
|
||||
second.append(a.get(i));
|
||||
}
|
||||
}
|
||||
System.out.println(first.toString());
|
||||
System.out.println(second.toString());
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 2.4 MiB |
@@ -0,0 +1,51 @@
|
||||
import java.util.*;
|
||||
import java.util.regex.*;
|
||||
|
||||
public class P2895 {
|
||||
static String normalize(String s) {
|
||||
boolean neg = s.startsWith("-");
|
||||
String t = neg ? s.substring(1) : s;
|
||||
int i = 0;
|
||||
while (i < t.length() - 1 && t.charAt(i) == '0') i++;
|
||||
t = t.substring(i);
|
||||
if (t.equals("0")) neg = false;
|
||||
return neg ? ("-" + t) : t;
|
||||
}
|
||||
|
||||
static int cmpNum(String a, String b) {
|
||||
boolean na = a.startsWith("-");
|
||||
boolean nb = b.startsWith("-");
|
||||
if (na != nb) return na ? -1 : 1;
|
||||
String aa = na ? a.substring(1) : a;
|
||||
String bb = nb ? b.substring(1) : b;
|
||||
if (!na) {
|
||||
if (aa.length() != bb.length()) return aa.length() < bb.length() ? -1 : 1;
|
||||
int c = aa.compareTo(bb);
|
||||
return c < 0 ? -1 : (c > 0 ? 1 : 0);
|
||||
} else {
|
||||
if (aa.length() != bb.length()) return aa.length() > bb.length() ? -1 : 1;
|
||||
int c = aa.compareTo(bb);
|
||||
return c > 0 ? -1 : (c < 0 ? 1 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Scanner in = new Scanner(System.in);
|
||||
StringBuilder input = new StringBuilder();
|
||||
while (in.hasNextLine()) {
|
||||
if (input.length() > 0) input.append('\n');
|
||||
input.append(in.nextLine());
|
||||
}
|
||||
Matcher m = Pattern.compile("-?\\d+").matcher(input.toString());
|
||||
List<String> nums = new ArrayList<>();
|
||||
while (m.find()) nums.add(normalize(m.group()));
|
||||
nums.sort(P2895::cmpNum);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < nums.size(); i++) {
|
||||
if (i > 0) sb.append(',');
|
||||
sb.append(nums.get(i));
|
||||
}
|
||||
System.out.println(sb.toString());
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 2.5 MiB |
@@ -0,0 +1,27 @@
|
||||
import java.util.*;
|
||||
|
||||
public class P2966 {
|
||||
static long maxPrimeFactor(long n) {
|
||||
if (n <= 1) return 1;
|
||||
long max = -1;
|
||||
while ((n & 1) == 0) { max = 2; n >>= 1; }
|
||||
for (long i = 3; i * i <= n; i += 2) {
|
||||
while (n % i == 0) { max = i; n /= i; }
|
||||
}
|
||||
if (n > 1) max = n;
|
||||
return max;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Scanner in = new Scanner(System.in);
|
||||
List<Long> nums = new ArrayList<>();
|
||||
while (in.hasNextLong()) nums.add(in.nextLong());
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < nums.size(); i++) {
|
||||
if (i > 0) sb.append(',');
|
||||
sb.append(maxPrimeFactor(nums.get(i)));
|
||||
}
|
||||
System.out.println(sb.toString());
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 2.5 MiB |
@@ -0,0 +1,36 @@
|
||||
import java.util.*;
|
||||
|
||||
public class P2967 {
|
||||
public static void main(String[] args) {
|
||||
Scanner in = new Scanner(System.in);
|
||||
if (!in.hasNextLong()) { in.close(); return; }
|
||||
long n = in.nextLong();
|
||||
boolean neg = n < 0;
|
||||
if (neg) n = -n;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (neg) sb.append('-');
|
||||
if (n == 1) {
|
||||
sb.append('1');
|
||||
System.out.println(sb.toString());
|
||||
in.close();
|
||||
return;
|
||||
}
|
||||
long p = 2;
|
||||
boolean first = true;
|
||||
while (n > 1 && p * p <= n) {
|
||||
while (n % p == 0) {
|
||||
if (!first) sb.append('*');
|
||||
sb.append(p);
|
||||
first = false;
|
||||
n /= p;
|
||||
}
|
||||
p = (p == 2) ? 3 : (p + 2);
|
||||
}
|
||||
if (n > 1) {
|
||||
if (!first) sb.append('*');
|
||||
sb.append(n);
|
||||
}
|
||||
System.out.println(sb.toString());
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 2.5 MiB |
@@ -0,0 +1,17 @@
|
||||
import java.util.*;
|
||||
|
||||
public class PTable {
|
||||
public static void main(String[] args) {
|
||||
Scanner in = new Scanner(System.in);
|
||||
int n = in.nextInt();
|
||||
for (int i = 1; i <= n; i++) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int j = 1; j <= n; j++) {
|
||||
if (j > 1) sb.append(' ');
|
||||
sb.append(i * j);
|
||||
}
|
||||
System.out.println(sb.toString());
|
||||
}
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 2.4 MiB |
@@ -0,0 +1,17 @@
|
||||
import java.util.*;
|
||||
|
||||
public class P2969 {
|
||||
public static void main(String[] args) {
|
||||
Scanner in = new Scanner(System.in);
|
||||
int n = in.nextInt();
|
||||
for (int i = 0; i < n; i++) {
|
||||
int stars = i <= n / 2 ? (2 * i + 1) : (2 * (n - i - 1) + 1);
|
||||
int spaces = (n - stars) / 2;
|
||||
StringBuilder row = new StringBuilder();
|
||||
for (int s = 0; s < spaces; s++) row.append(' ');
|
||||
for (int k = 0; k < stars; k++) row.append('*');
|
||||
System.out.println(row.toString());
|
||||
}
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 2.4 MiB |
@@ -0,0 +1,26 @@
|
||||
import java.util.*;
|
||||
|
||||
public class P2984 {
|
||||
public static void main(String[] args) {
|
||||
Scanner in = new Scanner(System.in);
|
||||
int n = in.nextInt();
|
||||
List<Long> prev = new ArrayList<>();
|
||||
for (int row = 1; row <= n; row++) {
|
||||
List<Long> cur = new ArrayList<>(row);
|
||||
long val = 1;
|
||||
for (int i = 0; i < row; i++) {
|
||||
if (i == 0) val = 1;
|
||||
else val = cur.get(i - 1) * (row - i) / i;
|
||||
cur.add(val);
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < cur.size(); i++) {
|
||||
if (i > 0) sb.append(' ');
|
||||
sb.append(cur.get(i));
|
||||
}
|
||||
System.out.println(sb.toString());
|
||||
prev = cur;
|
||||
}
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 2.4 MiB |
@@ -0,0 +1,14 @@
|
||||
import java.util.*;
|
||||
|
||||
public class P2989 {
|
||||
public static void main(String[] args) {
|
||||
Scanner in = new Scanner(System.in);
|
||||
int n = in.nextInt();
|
||||
for (int i = 0; i < n; i++) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int j = 0; j < n; j++) sb.append('V');
|
||||
System.out.println(sb.toString());
|
||||
}
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 2.5 MiB |
@@ -0,0 +1,39 @@
|
||||
import java.util.*;
|
||||
|
||||
public class P2975 {
|
||||
public static void main(String[] args) {
|
||||
Scanner in = new Scanner(System.in);
|
||||
StringBuilder all = new StringBuilder();
|
||||
if (in.hasNextLine()) {
|
||||
all.append(in.nextLine());
|
||||
while (in.hasNextLine()) {
|
||||
all.append('\n');
|
||||
all.append(in.nextLine());
|
||||
}
|
||||
}
|
||||
Map<Character, Integer> cnt = new HashMap<>();
|
||||
for (int i = 0; i < all.length(); i++) {
|
||||
char c = all.charAt(i);
|
||||
if (c == '\r' || c == '\n') continue;
|
||||
cnt.put(c, cnt.getOrDefault(c, 0) + 1);
|
||||
}
|
||||
char bestChar = 0;
|
||||
int best = -1;
|
||||
for (Map.Entry<Character, Integer> e : cnt.entrySet()) {
|
||||
char c = e.getKey();
|
||||
int v = e.getValue();
|
||||
if (v > best || (v == best && c < bestChar)) {
|
||||
best = v;
|
||||
bestChar = c;
|
||||
}
|
||||
}
|
||||
if (best < 0) {
|
||||
System.out.println();
|
||||
System.out.println(0);
|
||||
} else {
|
||||
System.out.println(bestChar);
|
||||
System.out.println(best);
|
||||
}
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 2.5 MiB |
@@ -0,0 +1,18 @@
|
||||
import java.util.*;
|
||||
|
||||
public class P2977 {
|
||||
public static void main(String[] args) {
|
||||
Scanner in = new Scanner(System.in);
|
||||
if (!in.hasNextInt()) { in.close(); return; }
|
||||
int n = in.nextInt();
|
||||
int[] a = new int[n];
|
||||
for (int i = 0; i < n; i++) a[i] = in.nextInt();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (i > 0) sb.append(' ');
|
||||
sb.append(a[i] + 1);
|
||||
}
|
||||
System.out.println(sb.toString());
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 2.5 MiB |