HDUOJ1195 OpenLock简单遍历
来源:互联网 发布:热血征途2008java 编辑:程序博客网 时间:2024/06/11 04:26
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class OpenLock2 {
static int[][] seq = new int[][] { { 1, 2, 3, 4, 0 }, { 1, 2, 4, 3, 1 }, { 1, 3, 2, 4, 1 }, { 1, 3, 4, 2, 2 }, { 1, 4, 2, 3, 2 }, { 1, 4, 3, 2, 3 }, { 2, 1, 3, 4, 1 }, { 2, 1, 4, 3, 2 }, { 2, 3, 1, 4, 2 }, { 2, 3, 4, 1, 3 }, { 2, 4, 1, 3, 3 }, { 2, 4, 3, 1, 4 }, { 3, 1, 2, 4, 2 }, { 3, 1, 4, 2, 3 }, { 3, 2, 1, 4, 3 }, { 3, 2, 4, 1, 4 }, { 3, 4, 1, 2, 4 }, { 3, 4, 2, 1, 5 }, { 4, 1, 2, 3, 3 }, { 4, 1, 3, 2, 4 }, { 4, 2, 1, 3, 4 }, { 4, 2, 3, 1, 5 }, { 4, 3, 1, 2, 5 }, { 4, 3, 2, 1, 6 } };static int[] org;static int[] pwd;static int step;public static void main(String[] args) throws FileNotFoundException { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); sc = new Scanner(new File("src/file/openlock")); int T = sc.nextInt(); for (int t = 0; t < T; t++) { org = new int[4]; pwd = new int[4]; step=100; char[] tmpr1 = sc.next().toCharArray(); char[] tmpr2 = sc.next().toCharArray(); for (int i = 0; i < 4; i++) { org[i] = tmpr1[i] - 48; pwd[i] = tmpr2[i] - 48; } for(int i=0;i<24;i++){ if(seq[i][4]>=step) continue; CacuStep(i); } System.out.println(step); }}private static void CacuStep(int no) { // TODO Auto-generated method stub int tmps=0; tmps+=seq[no][4]; for(int i=0;i<4;i++){ int tmp=(org[seq[no][i]-1]-pwd[i]+9)%9; if(tmp>4) tmp=9-tmp; tmps+=tmp; } if(tmps<step) step=tmps;}
}
sample input:
4
1234
4321
8679
5564
1234
2144
1111
9999
sample output:
6
9
2
4
0 0
- HDUOJ1195 OpenLock简单遍历
- 简单的ArrayList遍历
- 树的简单遍历
- struts2简单遍历Map
- python 简单遍历文件...
- 简单遍历json数据
- 简单的Vector遍历
- jq简单遍历对象
- 简单二叉树遍历
- 数组简单遍历
- 简单的遍历拓展
- 简单二叉排序树 二叉树遍历
- 简单的递归遍历树
- 一个简单的Mysql 遍历
- javascript遍历简单json数据
- 遍历 HashMap简单的方式
- opencv GPU 简单遍历图像
- 图的简单深度遍历
- Java 1.5,1.6,1.7,1.8新特性
- 关于void*与void**的区别
- 斯科特.杨《如何高效学习》
- mac 安装 composer
- static关键字学习笔记
- HDUOJ1195 OpenLock简单遍历
- FFMPEG avformat_find_stream_info替换
- 每日一题(15): poj2533
- ebtables/iptables interaction on a Linux-based bridge
- NumPy之二:数组形状操作
- 图像处理与计算机视觉基础,经典以及最近发展
- Linux I2C驱动个人理解(二)
- spring cloud微服务框架 第四天
- 移动端input上传调用相机