一、题目大意

模拟一个开组合的密码锁过程。就像电影你开保险箱一样,左转几圈右转几圈的就搞定了。这个牌子的锁呢,也有它独特的转法。这个锁呢,有一个转盘,刻度为0~39。在正北方向上有一个刻度指针。它的密码组合有三个数,开锁的套路为:先把刻度盘顺时针转两圈,然后再顺时针转到第一个数,再把刻度盘逆时针转一圈,再逆时针转到第二个数,最后再顺时针转到第三个数。这里的转到那个数是指将刻度盘上的数转到指针处。起始位置和组合密码有标准输入给出。求圆盘转过的总度数(顺时针加上逆时针)。注意刻度盘上还有一个凸起的圆盘,这个是不能转的。

二、题解

这个过程有一个不变的度数就是转的3圈数,1080度。然后就是顺时针和逆时针两种情况下,一个数转到另一个数要转的度数。顺时针情况下,从起始到结果的计算公式为:

result +=end > start  ? (40+start-end) * 9 : (start-end) * 9;,二逆时针则是:result+=end > start ? (end-start) * 9 : (40+end-start) * 9;

三、java代码

import java.util.Scanner;
public class Main{ public static void main(String args[]){
Scanner sc=new Scanner(System.in);
int ini,one,two,three;
while(true){
int result=1080;
ini=sc.nextInt();
one=sc.nextInt();
two=sc.nextInt();
three=sc.nextInt();
if(ini+one+two+three==0)
break;
result+=one > ini ?(40+ini-one) * 9:(ini-one) * 9;
result+=two > one ?(two-one) * 9:(40+two-one) * 9;
result+=three > two ?(40+two-three) * 9:(two-three) * 9;
System.out.println(result);
}
}
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

Poj 2304 Combination Lock(模拟顺、逆时钟开组合锁)的更多相关文章

  1. hihocoder-第六十一周 Combination Lock

    题目1 : Combination Lock 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Finally, you come to the interview roo ...

  2. Combination Lock

    时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Finally, you come to the interview room. You know that a Micr ...

  3. hihocoder #1058 Combination Lock

    传送门 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Finally, you come to the interview room. You know that a ...

  4. 贪心 Codeforces Round #301 (Div. 2) A. Combination Lock

    题目传送门 /* 贪心水题:累加到目标数字的距离,两头找取最小值 */ #include <cstdio> #include <iostream> #include <a ...

  5. Codeforces Round #301 (Div. 2) A. Combination Lock 暴力

    A. Combination Lock Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/540/p ...

  6. Hiho----微软笔试题《Combination Lock》

    Combination Lock 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Finally, you come to the interview room. You ...

  7. CF #301 A :Combination Lock(简单循环)

    A :Combination Lock 题意就是有一个密码箱,密码是n位数,现在有一个当前箱子上显示密码A和正确密码B,求有A到B一共至少需要滚动几次: 简单循环:

  8. A - Combination Lock

    Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Description Scroog ...

  9. HDU 3104 Combination Lock(数学题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=3104 Problem Description A combination lock consists ...

随机推荐

  1. 【python】-- RabbitMQ 安装、基本示例、轮询机制

    RabbitMQ MQ全称为Message Queue, 是一种分布式应用程序的的通信方法,它是消费-生产者模型的一个典型的代表,producer往消息队列中不断写入消息,而另一端consumer则可 ...

  2. centos7 运行postgres 数据库脚本db.sql

    [root@localhost ~]# su postgresbash-4.2$ psqlcould not change directory to "/root": Permis ...

  3. codeforces Gravity Flip 题解

    版权声明:本文作者靖心,靖空间地址:http://blog.csdn.net/kenden23/,未经本作者同意不得转载. https://blog.csdn.net/kenden23/article ...

  4. html_dom类读取

    上传类文件以后,有三种方式调用这个类:从url中加载html文档从字符串中加载html文档从文件中加载html文档 复制代码 代码如下: <?php// 新建一个Dom实例$html = new ...

  5. Kindeditor API

    根据map规则删除range中的element或attribute. cmd.remove({ span : '*', div : 'class,border' });   commonNode(ma ...

  6. J2EE SSH框架整合教程

    本文仅作为学习和研究的参考,与实际项目使用技术有所不同,由于作者水平有限,错误疏漏在所难免,请各位看官批评指教. 项目的源代码放在:https://github.com/Frank-Pei/SSHIn ...

  7. Data Structure Array: Maximum of all subarrays of size k

    http://www.geeksforgeeks.org/maximum-of-all-subarrays-of-size-k/ #include <iostream> #include ...

  8. inline-block元素的4px空白间距解决方案

    http://www.jb51.net/css/68785.html  inline-block元素的4px空白间距解决方案 

  9. CSS3响应式侧边菜单

    在线演示 本地下载

  10. <再看TCP/IP第一卷>关于网络层及协议细节---ICMP协议几个要注意的地方

    在TCP/IP协议族中,ICMP协议是一个介于网络层和传输层中间的一个协议,许多材料都会认为ICMP是网络层的一个部分,但是ICMP协议的报头是被包裹在IP协议之中的,而UDP协议又可以被ICMP协议 ...