因为某个der比赛只支持Java和JS参赛,临时速成Java,这里是赶鸭子上架的ACMJava模板。
东大模板
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
| import static java.lang.Math.*; import static java.util.Arrays.*; import java.io.*; import java.util.*; public class Main { static boolean LOCAL = System.getSecurityManager() == null; static boolean TO_FILE = true; Scanner sc = new Scanner(System.in); void run() { } void debug(Object... os) { System.err.println(deepToString(os)); } public static void main(String[] args) { if (LOCAL) { try { System.setIn(new FileInputStream("./bin/in.txt")); } catch (Throwable e) { LOCAL = false; } } if (TO_FILE) { try { System.setOut(new PrintStream("./src/output.txt")); } catch (FileNotFoundException e) { e.printStackTrace(); } } new Main().run(); } }
|
Kattio
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
| class Kattio extends PrintWriter { private BufferedReader r; private StringTokenizer st; public Kattio() { this(System.in, System.out); } public Kattio(InputStream i, OutputStream o) { super(o); r = new BufferedReader(new InputStreamReader(i)); } public Kattio(String intput, String output) throws IOException { super(output); r = new BufferedReader(new FileReader(intput)); } public String next() { try { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(r.readLine()); return st.nextToken(); } catch (Exception e) {} return null; } public int nextInt() { return Integer.parseInt(next()); } public double nextDouble() { return Double.parseDouble(next()); } public long nextLong() { return Long.parseLong(next()); } }
|
杂项
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
| import java.util.*;
import java.math.BigDecimal; import java.math.*; public class Main { public static void main(String[] args) { BigInteger[] sum=new BigInteger[105]; Scanner cin = new Scanner(System.in); int t = cin.nextInt();
while (t--!=0) { BigInteger a = cin.nextBigInteger(); BigInteger b = cin.nextBigInteger(); BigInteger c; c = a.add(b); c = a.subtract(b); c = a.multiply(b); c = a.divide(b); c = a.remainder(b); c = a.mod(b); c = BigInteger.ZERO; c = BigInteger.ONE; c = BigInteger.TEN; c = BigInteger.valueOf(7); int n = 7; c = BigInteger.valueOf(n); c = a.pow(n); c = a.gcd(b); c = a.abs(); c = a.max(b); c = a.min(b); n = a.compareTo(b); a.equals(b); a.isProbablePrime(2); System.out.println(c); System.out.print(c); System.out.println(a+" "+b); BigDecimal d = cin.nextBigDecimal(); BigDecimal e = cin.nextBigDecimal(); BigDecimal f = d.add(e); f = d.setScale(2); f = d.setScale(2,BigDecimal.ROUND_DOWN); f = d.setScale(2,BigDecimal.ROUND_UP); f = d.setScale(2,BigDecimal.ROUND_HALF_DOWN); f = d.setScale(2,BigDecimal.ROUND_HALF_UP); Dog[]dogs = new Dog[] {d1,d2,d3,d4,d5}; Arrays.sort(dogs,new ByWeightComparator()); } } }
class Dog { private String name; private int weight; public Dog(String name, int weight) { this.setName(name); this.weight = weight; } public int getWeight() { return weight; } public void setWeight(int weight) {this.weight = weight;} public void setName(Stringname) {this.name = name;} public String getName() {return name;} } class ByWeightComparator implements Comparator { public final int compare(Object pFirst, Object pSecond) { int aFirstWeight = ((Dog)pFirst).getWeight(); int aSecondWeight = ((Dog)pSecond).getWeight(); int diff = aFirstWeight - aSecondWeight; if(diff >= 0) return -1; else if(diff < 0) return 1; return 0; } }
|
类STL
优先队列PriorityQueue
类及其迭代器实现Collection和Iterator接口的所有可选方法,PriorityQueue是非线程安全的,所以Java提供了PriorityBlockingQueue(实现BlockingQueue接口)用于Java多线程环境。默认是小根堆。PriorityQueue的iterator()不保证以任何特定顺序遍历队列元素。若想按特定顺序遍历,先将队列转成数组,然后排序遍历。
1
| PriorityQueue<Integer> queue = new PriorityQueue<>();
|
大根堆
1 2 3 4 5 6 7 8
| PriorityQueue<Integer> queue = new PriorityQueue<>(new Comparator<Integer>() { @Override public int compare(Integer o1, Integer o2) { return o2.compareTo(o1); } }); PriorityQueue<Integer> queue = new PriorityQueue<>((o1, o2)->o2.compareTo(o1)); PriorityQueue<Integer> queue = new PriorityQueue<>((o1, o2)->o2.compareTo(o1));
|
操作
1 2 3 4 5 6 7 8 9 10 11 12 13
| queue.add(E e); queue.clear(); queue.offer(12); queue.offer(15); queue.offer(10); queue.peek(); queue.poll(); queue.size(); queue.toArray(); while(!queue.isEmpty()) { int t = queue.poll(); System.out.println(t); }
|