luogu
AllekhoCn
这个作者很懒,什么都没留下…
展开
-
p1002过河卒
注意马位置可能在边缘,导致确定位置为负。因此棋盘整体横纵坐标+2,规避问题。分解为f[i][j] = f[i-1][j] + f[i][j-1]善用数组解决问题,循环判定马限制的位置。原创 2023-03-12 09:45:04 · 38 阅读 · 0 评论 -
P1603
关注取值大小,12位长度超INT: 4 * 10^9 需用 Long:10^19。大胆用HashMap/ ArrayList。考虑无数字单词情况,输出0。原创 2023-03-09 18:55:58 · 52 阅读 · 0 评论 -
Luogu p1045
思路:快速幂 + 高精数 快速幂见前帖 注意运算过程中只保留后500位,否则会MLE。 ANS MOD 10^500 求2^P - 1的位数: N = floor(log10(2^n) + 1) = floor(n * log10(2)) + 1) Code: import java.util.Scanner; import java.util.*; import java.io.*; import java.math.*; public class Main { public stat..原创 2022-05-08 15:33:44 · 51 阅读 · 0 评论 -
Luogu p1249
思路:若干互不相同自然数,通过规律可知: 当N > 5时,将N分解为尽可能多的非1数,所得的乘积最大。e.g. 5 -> 2, 3 6 -> 2, 4 故从2开始累加 2 + 3 + 4 + ..., 但在这种情况下,会出现累加和大于目标数的情况。此时若改变数列后方使之变小则...原创 2022-05-08 15:26:37 · 53 阅读 · 0 评论 -
Luogu P1803
利用类进行排序: CLASS必为STATIC 因为要被MAIN 调用,STATIC 类只能调用外部STATIC类 CLASS内可以包含多个变量 利用ARRAYS.SORT排序: public static class cmp implements Comparator<exam/*自己创建的类,例子里是exam*/>{ @Override public int compare(exam a, exam b) { if (a...原创 2022-04-07 21:18:01 · 45 阅读 · 0 评论 -
快排JAVA实现
private static int[] in; //待排数组0位置为空,因为该算法可能出现j小于0 //的情况,预留空间。输入数据时从1开始。 //打乱in的原始顺序,以防N^2 private static void swap(int.原创 2022-03-28 17:46:26 · 313 阅读 · 0 评论 -
快速幂方法
求:a ^ b 一般算法:计算b次 快速算法: 1. b转换为二进制:e.g. b = 11, 001011 2. 每次判断 b 的最后一位是否为1,若为1,则对应的答案乘上此时二进制代表的次数, 并将b向右移动一位,更新a = a^2 a a^2 a^4 a^8 3.若不为1,则只更新a^2, 移位观察b的下一位,直到b = 0; while (p > 0) { if ((p & 1) == 1) { //与运算,判断是否末位为1 ans.原创 2022-03-24 18:39:36 · 53 阅读 · 0 评论 -
Luogu1957
The biggest problem is determining the type of first input of each line. Solu: Character.isAlphebet( ) // true for letter Character.isDigit( ) // true for digit After the judge, choose to input the next 2 or 1 integer.原创 2022-03-21 18:58:32 · 46 阅读 · 0 评论 -
Luogu P1217
Outline: Output all palindromes, then determine whether it’s a prime or not. Cavets: Prime palindromes have the following features: 1. All palindromes have even digits, e.g. 1221, 111111 etc. are divisible by 11 (except 11 itself), so they’re not prime. 2.原创 2022-03-16 17:01:22 · 70 阅读 · 0 评论 -
Luogu p1888 GCD最大公约数
Cavets: The most difficult part of it is the fraction reduction process, that is, finding the greatest common divisor(gcd) of the numerator and denominator, and then dividing them using the gcd. Euclidean algorithm: Find the gcd! Basic idea: larger mod sm.原创 2022-03-11 14:57:04 · 103 阅读 · 0 评论 -
Luogu p2181
Basic idea: Two and only two lines can create an intersection according to the instruction. So it is basically a permutations and combinations question: how many sets of 4 vertex does the graph have? Since the sequence of the 4 vertex won’t affect the fin.原创 2022-03-10 20:14:06 · 93 阅读 · 0 评论 -
Luogu p5705
Luogu p5705 输入一个不小于 100100 且小于 10001000,同时包括小数点后一位的一个浮点数,例如 123.4123.4 ,要求把这个数字翻转过来,变成 4.3214.321 并输出。 CODE: import java.util.Scanner; public class Main { public static void main(String args[]) { Scanner sc = new Scanner(System.in); String input = sc.next原创 2022-03-08 13:35:08 · 160 阅读 · 0 评论