
java算法
rjbusiness
编程之路不能放弃你的话就只能风风光光的迎娶你了虽然无奈但我会接受
展开
-
第100002个素数
.. 请问,第100002(十万零二)个素数是多少? 请注意:“2” 是第一素数,“3” 是第二个素数,依此类推。[/b][/color][/size][code="java"] public static void main(String[] args){ int n = 1; int i = 3; while(n原创 2013-07-08 12:59:15 · 433 阅读 · 0 评论 -
跳格子
/则下一次富老师最多跳k+i个格,问富老师最少几次可以跳到终点。//例如:下图所示的情况,k=3时,富老师最少4次跳到终点。//S 0 0 2 1 0 0 3 0 1 0 0 0 0 Epublic class Title25 { public static void main(String[] args){ f(); } // public static void f(){ int[] a = {0,3,4,20,0,0,3,0,1,0,0,0}; int原创 2013-05-03 14:06:30 · 285 阅读 · 0 评论 -
警察110
iptEngine;import javax.script.ScriptEngineManager;import javax.script.ScriptException;public class test { public static void main(String[] args){ String s="123456789"; f(s,1); } // 计算每次的值; 使用JavaScript 对表达式直接进行运算 publ原创 2013-05-03 14:06:50 · 133 阅读 · 0 评论 -
连续多个数的最小公倍数
原创 2013-05-03 14:07:18 · 217 阅读 · 0 评论 -
递归实现字符串反转
{ if(x==null || x.length()原创 2013-05-06 21:05:10 · 158 阅读 · 0 评论 -
孪生素数
原创 2013-05-04 08:42:10 · 210 阅读 · 0 评论 -
圆周率
。//有了计算机,圆周率的计算变得十分容易了。如今,人们创造了上百种方法求π的值。其中比较常用且易于编程的是无穷级数法。//π/4 = 1 – 1/3 + 1/5 – 1/7 + 1/9 - …//是初学者特别喜欢的一个级数形式,但其缺点是收敛太慢。//π/2 = 1 + 1/3 +1/3*2/5 + 1/3*2/5*3/7 + 1/3*2/5*3/7*4/9 + …public class Title1 {// π/2 = 1 + 1/3 +1/3*2/5 + 1/3*2/2013-05-02 16:30:19 · 190 阅读 · 0 评论 -
正方形的回文
public class 正方形的回文 { public static void main(String[] args){ Scanner input = new Scanner(System.in); int n = Integer.parseInt(input.next()); int[][] arr = new int[n][n]; int x = 0; int y = 0; int temp = 1; //从开始到回文结束的值 arr[x2013-05-02 16:23:43 · 151 阅读 · 0 评论 -
字符串处理 镜像对称 中心对称
2013-05-01 09:52:43 · 357 阅读 · 0 评论 -
地铁换乘-取最佳路线最低票价
rator;import java.util.Map;import java.util.Set;////为解决交通难题,某城市修建了若干条交错的地铁线路,线路名及其所属站名如stations.txt所示。////线1//苹果园//....//四惠东////线2//西直门//车公庄//....//建国门////线4//....////其中第一行数据为地铁线名,接下来是该线的站名。//当遇到空行时,本线路站名结束。//2013-04-30 17:49:01 · 172 阅读 · 0 评论 -
平均距离
原创 2013-04-30 08:51:23 · 484 阅读 · 0 评论 -
最长连续字符
("100011110000111111")); } public static int getMaxContinuity(String s){ int max_1 = 0; int max_0 = 0; int n_1 = 0; //当前 1 连续的次数 int n_0 = 0; // 当前0连续的次数 for(int i=0;imax_1){ max_1 = n_1; } if(n_0>max_0){2013-05-03 16:06:41 · 123 阅读 · 0 评论 -
分解质因式 完数
原创 2013-05-04 08:42:26 · 101 阅读 · 0 评论 -
古代赌局
原创 2013-07-08 12:59:46 · 138 阅读 · 0 评论 -
地址转换
2013-07-07 16:41:38 · 140 阅读 · 0 评论 -
全排列,精简
"2","3","4","5","6","7","8","9"}; long begin = System.currentTimeMillis(); pailie(0,ss.length-1,ss); for(int i=0;i2013-07-07 13:49:29 · 82 阅读 · 0 评论 -
买不到的数目,组合问题
2013-07-06 19:02:12 · 79 阅读 · 0 评论 -
字符串的拼接
2013-07-04 12:42:15 · 159 阅读 · 0 评论 -
取小数的循环体
2013-07-03 17:17:10 · 155 阅读 · 0 评论 -
使用二进制替代解决全排列问题
2013-06-29 17:04:11 · 249 阅读 · 0 评论 -
双层棱形
原创 2013-05-06 21:04:10 · 114 阅读 · 0 评论 -
拍七游戏
2013-05-04 09:25:33 · 233 阅读 · 0 评论 -
连续平方数
3^2 + 4^2 + ...////请看下面的公式:////1^2 + 2^2 + 3^2 + 4^2 + ... + x^2 = y^2////是不是存在整数x,y,使得公式成立呢?显然x=y=1 勉强成立,数学上称为“平凡解”。////你的任务是寻找该方程的某个非平凡解(实际上只有1个)。//非平凡解,那么x 和 y 的值不相等//请填写该公式中x所代表的数字。[/b][/color][/size][code="java"]public2013-05-04 09:14:43 · 266 阅读 · 0 评论 -
文件格式转换 读入输出
i=0;i原创 2013-04-30 08:51:52 · 123 阅读 · 0 评论 -
第N个素数
能被 1 或者自身整除的数public class Sushu { public static void main(String[] args){ Scanner input = new Scanner(System.in); System.out.println("input aim num:"); int aim = Integer.parseInt(input.next()); int current = 2; int sum = 0;2013-04-29 11:34:14 · 229 阅读 · 0 评论 -
基因母牛问题
se if(n==3){ return 2; }else if(n==4){ return 3; }else{ return cow(n-1)+n-4; } }}[/code]2013-04-17 19:50:07 · 100 阅读 · 0 评论 -
方正的主对角线为:“上三角”
2013-04-17 14:10:16 · 165 阅读 · 0 评论 -
二维数组 元素的连续求解
的连续存放的0的个数最多,是几个0。注意,是“连续”。 public static void f(){ int[][] a = {{0,1,2,4,0,0,3,0,1,0},{0,0,2,4,5,0,3,0,1,1},{0,1,0,0,0,0,3,0,1,0}}; int[][] count = new int[a.length][1]; // 行 int maxCountH = 0; for(int i=0;i2013-04-16 18:59:21 · 288 阅读 · 0 评论 -
字符串对称 计算插入字符最小对称数
: 判断首尾是否相等 , 有两种情况,一次的从两侧向中间推移 * a b c d * */ public static int symmetry(String source){ //字符串对称 int length = source.length(); int count = 0; // 计算的是加入字母的个数 int compareIndex = length-1; // 记录的是最右边的索引 // for(int i=2013-04-15 10:53:52 · 212 阅读 · 0 评论 -
数组转换 奇数 偶数排序倒置
2013-04-15 10:19:25 · 205 阅读 · 0 评论 -
字符串处理 相同的子串
ring str1 = "abcfabcd"; String str2 = "arcfabdabce"; // 获取两个字符的所有字串的情况 //字符串1 ArrayList list1 = new ArrayList(); for(int i=0;i2013-04-14 13:44:23 · 197 阅读 · 0 评论 -
字符串处理 子串不重复
。 public static void f3(){ String str = "aaab"; ArrayList arrayStr = new ArrayList(); for(int i=0;i2013-04-14 11:36:15 · 186 阅读 · 0 评论 -
字符串处理 字串问题
//题目:一个字符串中,哪个子串(长度要求大于等于2)重复出现次数最多,如果有多个子串重复次数相同,取长度最大的子串。 // 1、求出所有的字串 // 2、找出对应字串在字符串中出现的次数 // 3、在所有的次数中找出最大值 // 4、根据最大值找出对应的字符串 // 分步思想 , 一步步解决问题 详细解剖解题 public static void f(){ String str = "abcfabcdabce"; ArrayList l2013-04-14 11:03:12 · 112 阅读 · 0 评论 -
字符串处理 去除重复
现一次。【样例】输入:Where there is a will , there is a way输出:Where there is a will , wayimport java.util.ArrayList;//where there is a ,ther is a willpublic class Title5 { public static void main(String[] args){ f(); } //主要算法 public原创 2013-04-13 09:05:40 · 202 阅读 · 0 评论 -
蓝桥杯字符集处理 -字符串
tatic void f(){ String newStr = ""; String message="you dd me want money20009program3225iuoiu89453ty67s"; String[] s = message.split(" "); for(int i=0;i2013-04-11 00:08:52 · 113 阅读 · 0 评论 -
国际软件大赛-平方数问题
/196//961public class My{ public static void f(int[] a, int n) { if(n==a.length-1) { int k = 0; //a : 1 9 6 for(int i=0; i2013-04-17 19:52:57 · 74 阅读 · 0 评论 -
字符串处理 倒转
2013-04-17 19:54:35 · 95 阅读 · 0 评论 -
DP 动态规划算法的设计步骤及解题思想
2013-04-28 10:00:07 · 186 阅读 · 0 评论 -
21位数的花朵数
0- 9 在 21 位数中出现的次数 * * 使用递归,找到每个数出现次数的可能,找到一种结果计算一次; 看是否符合条件 * * */ //每次求出 0-9 的 21 次方 public static BigInteger p(int a){ BigInteger base = BigInteger.ONE; for(int i=0;i原创 2013-04-27 20:27:05 · 96 阅读 · 0 评论 -
进制转换-十进制转任意进制
对整数部分,用2去除,取其余数为转换后的二进制//整数数字,知道商为0的结束,注意得到的余数为所求结果的的地位;public class 进制转换 { public static void main(String[] args){ Scanner input = new Scanner(System.in); ArrayList list = new ArrayList(); System.out.println("结束的时候输入 00 !");2013-04-23 10:11:13 · 288 阅读 · 0 评论