hust 1051 - Combination Lock
来源:互联网 发布:iu脸型数据 编辑:程序博客网 时间:2024/06/05 10:11
原题链接:
http://acm.hust.edu.cn/problem/show/1051
1051 - Combination Lock
Time Limit: 1s Memory Limit: 128MB
Submissions: 156 Solved: 67
- DESCRIPTION
- Now that you're back to school for another term, you need to remember how to work the combination lock on your locker. A common design is that of the Master Brand, shown at right. The lock has a dial with 40 calibration marks numbered 0 to 39. A combination consists of 3 of these numbers; for example: 15-25-8. To open the lock, the following steps are taken: * turn the dial clockwise 2 full turns * stop at the first number of the combination * turn the dial counter-clockwise 1 full turn * continue turning counter-clockwise until the 2nd number is reached * turn the dial clockwise again until the 3rd number is reached * pull the shank and the lock will open. Given the initial position of the dial and the combination for the lock, how many degrees is the dial rotated in total (clockwise plus counter-clockwise) in opening the lock?
- INPUT
- Input consists of several test cases. For each case there is a line of input containing 4 numbers between 0 and 39. The first number is the position of the dial. The next three numbers are the combination. Consecutive numbers in the combination will be distinct. A line containing 0 0 0 0 follows the last case.
- OUTPUT
- For each case, print a line with a single integer: the number of degrees that the dial must be turned to open the lock.
- SAMPLE INPUT
0 30 0 305 35 5 350 20 0 207 27 7 270 10 0 109 19 9 190 0 0 0
- SAMPLE OUTPUT
135013501620162018901890
- HINT
- SOURCE
一道水题,就是题意比较难理解。
题意:表盘有40个刻度(0~39),有三个密码a,b,c,一个初始位置p,解锁步骤如下,①顺时针转动2圈,②顺时针转到刻度a,③逆时针转动一圈,④逆时针转到刻度b,⑤顺时针转到刻度c。要注意的就是转动的是刻度盘,所以逆时针和顺时针不要反了。
代码:
#include "stdio.h"int main(){int p,a,b,c,ans;while(scanf("%d%d%d%d",&p,&a,&b,&c)&&(a||b||c||p)){ans=40*3+(p+40-a)%40+(b+40-c)%40+(b+40-a)%40;printf("%d\n",ans*9);}return 0;}
0 0
- hust 1051 - Combination Lock
- Combination Lock
- Combination Lock
- fjnu 1501 Combination Lock
- 1501 Combination Lock
- poj 2304 Combination Lock
- 10550 - Combination Lock
- UVa 10550 - Combination Lock
- POJ2304 Combination Lock
- USACO 1.3 Combination Lock
- USACO Combination Lock
- Sicily 13857. Combination Lock
- CF Combination Lock
- A. Combination Lock
- USACO Combination Lock
- USACO 1.3 Combination Lock
- USACO 1.3 Combination Lock
- USACO-1.3:Combination Lock
- gcc编译选项
- uva10294 Arif in Dhaka(置换的等价类计数)
- 超详细linux系统硬件配置查看方法
- 1056. Mice and Rice (25)
- Java常用的正则表达式
- hust 1051 - Combination Lock
- Skia深入分析1——skia上下文
- Matlab FAQ
- 关于XPath总结
- Android 之网络
- Matlab图像处理学习笔记(四):多边形检测
- 两个上亿行的大文件取交集
- VirtualBox配置CentOS
- Android--将布局保存成图像