摘要:
有些HDOJ上的题目明明已经到O(n)算法了,比如1029题,时间复杂度已经最优了,但还是会TLE。主要原因是java的IO不够快。比如input是这样格式的:51 3 2 3 3111 1 1 1 1 5 5 5 5 5 571 1 1 1 1 1 1读每一组数据的时候,最好不要用sc.nextI... 阅读全文
摘要:
最小公倍数least common multiple (LCM).最大公约数greatest common divisor (GCD).代码如下: public static int lcm(int a, int b){ return a*b/gcd(a,b); } ... 阅读全文
摘要:
just use the java's printf function. It is like C's printf.System.out.printf("%.3f\n", x); 阅读全文
摘要:
Division by 3.发现一些规律:一个数的数字和相加能被三整除,那么这个数也能被3整除。(1)然后可以发现:连续三个整数并排在一起组成的数的数字和必然能被3整除。(2)最后通过(2)总结出:1.题目中的第3K个数,必然能被三整除。2.题目中的第3K + 1个数,其第2个数字到最末一个数字之和... 阅读全文
摘要:
it seems all stop methods of thread have been deprecated by java. so how to stop a thread then? it is actually simple, just use a boolean variable.pub... 阅读全文