- 浏览: 106235 次
- 性别:
- 来自: 广州
最新评论
-
xinhemei:
我试了试,发现gmail和163的不行。好像ajax请求失败了 ...
jQuery实现邮箱自动登录 -
酒鬼_yuan:
我正在找 谢谢了
关于yui的学习
import java.io.BufferedInputStream; import java.util.LinkedList; import java.util.Scanner; /** * @author NC * poj3126 * 筛素数+bfs * 最初判断素数是打算一个一个按照基本定义去判断,后来想到当case多的时候,有很多重复的操作 * 所以就找到了线性筛素数的模版,简单改了一下,得到了一张素数表,这样应该会快一点 * 而作bfs时 * 发现,每一步有39个方向.....如果要调试的话,应该很麻烦 * 果然当写完程序时,测试的样例都过不了,郁闷啊...... * 最后发现一个循环少了个=号...无语 */ public class Poj3126 { static boolean[] isPrime = Prime.getPrimes(10000); public static void main(String[] args) { Scanner scan = new Scanner(new BufferedInputStream(System.in)); int cas = scan.nextInt(); for (int i = 1; i <= cas; i++) { int start = scan.nextInt(); int end = scan.nextInt(); boolean[] isVisited = new boolean[10000]; int[] step = new int[10000]; LinkedList<Integer> queue = new LinkedList(); queue.addLast(start); isVisited[start] = true; while (!queue.isEmpty()) { int current = queue.pop(); if (current == end) { break; } for (int j = 0; j <= 9; j++) {//少了等号 int next1 = getNext(1, j, current); int next2 = getNext(2, j, current); int next3 = getNext(3, j, current); int next4 = getNext(4, j, current); if (!isVisited[next1]) { queue.addLast(next1); step[next1] = step[current] + 1; isVisited[next1] = true; } if (!isVisited[next2]) { queue.addLast(next2); step[next2] = step[current] + 1; isVisited[next2] = true; } if (!isVisited[next3]) { queue.addLast(next3); step[next3] = step[current] + 1; isVisited[next3] = true; } if (!isVisited[next4]) { queue.addLast(next4); step[next4] = step[current] + 1; isVisited[next4] = true; } } } System.out.println(step[end]); } } public static int getNext(int flag, int i, int current) { int next = 0; if (flag == 1) { if (i == 0) { return current; } next = current % 1000 + i * 1000; } if (flag == 2) { int t = current / 1000; next = t * 1000 + current % 1000 % 100 + i * 100; } if (flag == 3) { int t = current / 100; int tt = current % 10; next = t * 100 + i * 10 + tt; } if (flag == 4) { next = current / 10 * 10 + i; } if (!isPrime[next]) { return current; } return next; } } /* 线性筛素数的一个方法,返回一个素数表 */ class Prime { public static boolean[] getPrimes(int n) { int i, j, k, x; boolean[] a = new boolean[n]; n++; n /= 2; int[] b = new int[(n + 1) * 2]; a[2] = true; a[3] = true; for (i = 1; i <= 2 * n; i++) { b[i] = 0; } for (i = 3; i <= n; i += 3) { for (j = 0; j < 2; j++) { x = 2 * (i + j) - 1; while (b[x] == 0) { a[x] = true; for (k = x; k <= 2 * n; k += x) { b[k] = 1; } } } } return a; } }
发表评论
-
poj3125简单模拟
2010-05-25 11:44 925import java.io.BufferedInputS ... -
还是水
2010-05-24 12:53 734import java.io.BufferedInputS ... -
Poj3085再水一下
2010-05-24 12:28 826import java.io.BufferedInputS ... -
Poj3673超水题
2010-05-24 12:12 823package easy; import java. ... -
Poj3278 广度优先搜索
2010-05-22 23:24 1288import java.io.BufferedInputS ... -
合唱队形
2010-05-09 21:45 2107#include <stdio.h> #incl ... -
动态规划经典问题 石子合并
2010-05-09 21:45 6060我们学校的oj的 #include & ... -
poj3199 高精
2010-05-09 21:44 926import java.io.BufferedInputS ... -
poj1002 郁闷的电话号码
2010-05-08 23:48 1231import java.io.BufferedInputS ... -
poj1298 无语。。。
2010-04-24 23:24 978import java.io.BufferedInputStr ... -
poj1017 装箱问题 简单贪心
2010-04-18 16:56 2323import java.io.BufferedInpu ... -
poj1042 枚举+贪心算法
2010-04-18 00:45 1766import java.io.BufferedInputS ... -
zoj3197 Google Book 贪心算法
2010-04-15 23:54 1343#include <stdio.h> #defi ... -
Poj2453 an easy program
2010-04-09 00:19 834/* * To change this template, ... -
poj2299 递归与分治策略
2010-04-02 23:38 1401package hard; import java.io ... -
poj1723 数学问题
2010-04-02 15:31 993package middle; import jav ... -
Poj2524 并查集
2010-03-18 15:22 841package middle; import jav ... -
Poj1308 并查集
2010-03-18 15:21 1664package middle; import jav ... -
poj1405 高精
2010-02-28 11:09 1334import java.io.BufferedInputS ... -
poj1979 深度遍历
2010-02-27 20:56 1260问题重述 问题描述: ...
相关推荐
北大POJ3126-Prime Path 解题报告+AC代码
POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类
poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题...
POJ第1861题源码 POJ第1861题源码 POJ第1861题源码
3126 POJ 3414 POJ 2251 简单搜索技巧和剪枝 POJ 1010 :star: POJ 2362 POJ 1011(搜索+剪枝) POJ 1416 POJ 2676 POJ 1129:white_question_mark: 数据结构 串 POJ 1016 POJ 1035 POJ 3080 POJ 1936 排序(快排) ...
北大POJ1159-Palindrome 解题报告+AC代码
C语言 poj npu 西工大 C语言Poj答案全完整打包,给有需要的朋友
poj 3414解题报告poj 3414解题报告poj 3414解题报告poj 3414解题报告
poj分类poj分类poj分类poj分类
poj 1012解题报告poj 1012解题报告poj 1012解题报告poj 1012解题报告
poj 2329解题报告poj 2329解题报告poj 2329解题报告poj 2329解题报告
北大POJ2002-Squares 解题报告+AC代码
POJ1503解答 POJ1503解答,正确答案(已通过POJ)
poj 1659解题报告poj 1659解题报告poj 1659解题报告poj 1659解题报告
POJ1048,加强版的约瑟夫问题 难度中等
POJ1083的代码,POJ1083的代码,POJ1083的代码
poj 百练 题目分类 poj 百练 题目分类
POJ上的一道题目,自己写的代码,因为想下载别人的, 所以就放上了。
poj 1001答案
POJ2968代码有用,欢迎下载,POJ代码