Weird Clock

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3109    Accepted Submission(s): 1137

Problem Description
A weird clock marked from 0 to 59 has only a minute hand. It won't move until a special coin is thrown into its box. There are different kinds of coins as your options. However once you make your choice, you cannot use any other kind.
There are infinite number of coins of each kind, each marked with a number d ( 1 <= d <= 1000 ), meaning that this coin will make the minute hand move d times clockwise the current time. For example, if the current time is 45, and d = 2. Then the minute hand
will move clockwise 90 minutes and will be pointing to 15.

Now you are given the initial time s ( 1 <= s <= 59 ) and the coin's type d. Write a program to find the minimum number of d-coins needed to turn the minute hand back to 0.

 
Input
There are several tests. Each test occupies a line containing two positive integers s and d.

The input is finished by a line containing 0 0.

 
Output
For each test print in a single line the minimum number of coins needed. If it is impossible to turn the hand back to 0, output "Impossible".
 
Sample Input
30 1
0 0
 
Sample Output
1
题意:一个0~59分的时钟,只有分针,给你一个初始时刻s和单次转动次数d。叫你求出多少次以后可以转到0刻度。刚开始我是想着转n个d次,则有(s+n*d*s)%60==0这样一条公式,但是怎么提交都是错,后来看讨论区说是题意问题,再看看题目也没发现啥。最后看了题解,发现每转一次d将把当前的刻度视为单位转动刻度,而非一直是最开始的刻度,比如25 5,第一次到达(25+5*25)%60=30分,第二次则会到达(30+5*30)%60=0刻度,因此第二次就到了。若是刚开始错误的公式(s+n*d*s)%60==0,则n会等于7
代码:
#include<iostream>
#include<cstdio>
using namespace std;
int main(void)
{
int s,d,n;
bool ok;
while (~scanf("%d%d",&s,&d)&&(s||d))
{
ok=true;
n=0;//计数器要初始化为0,对应一开始就到达0刻度的情况
while (s%60!=0)
{
s=(s+s*d)%60;
n++;
if(n>=61)
{
ok=false;//标记变量
break;
}
}
if(ok)
cout<<n<<endl;
else
cout<<"Impossible"<<endl;
}
return 0;
}

HDU——1393Weird Clock(水题,注意题意)的更多相关文章

  1. hdu 5210 delete 水题

    Delete Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5210 D ...

  2. hdu 1251 (Trie水题)

    统计难题 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131070/65535 K (Java/Others)Total Submi ...

  3. hdu 5038 水题 可是题意坑

    http://acm.hdu.edu.cn/showproblem.php?pid=5038 就是求个众数  这个范围小 所以一个数组存是否存在的状态即可了 可是这句话真恶心  If not all ...

  4. HDU 4493 Tutor 水题的收获。。

    题目: http://acm.hdu.edu.cn/showproblem.php?pid=4493 题意我都不好意思说,就是求12个数的平均数... 但是之所以发博客,显然有值得发的... 这个题最 ...

  5. hdu 4802 GPA 水题

    GPA Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4802 Des ...

  6. HDU 5703 Desert 水题 找规律

    已知有n个单位的水,问有几种方式把这些水喝完,每天至少喝1个单位的水,而且每天喝的水的单位为整数.看上去挺复杂要跑循环,但其实上,列举几种情况之后就会发现是找规律的题了= =都是2的n-1次方,而且这 ...

  7. hdu 4493 Tutor 水题

    Tutor Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4493 D ...

  8. hdu 5495 LCS 水题

    LCS Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5495 Descr ...

  9. Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) A. Broken Clock 水题

    A. Broken Clock 题目连接: http://codeforces.com/contest/722/problem/A Description You are given a broken ...

随机推荐

  1. Leetcode重点 250题-前400 题

    删除不常考,面试低频出现题目 删除重复代码题目(例:链表反转206题,代码在234题出现过) 删除过于简单题目(例:100题:Same Tree) 删除题意不同,代码基本相同题目(例:136 & ...

  2. 【转】 树莓派初次启动攻略for Mac

    http://blog.csdn.net/rk2900/article/details/8632713/ 树莓派初次启动攻略for Mac made by Rk 感谢浙江大学<嵌入式系统> ...

  3. centos7中文显示为小方块~~啊啊啊 求大佬们解答

    这个问题困扰我很久了,刚好前几天注册了博客园,就想问问大佬们是怎么解决中文显示小方块的? 我试了很多办法,包括但不限于修改i18n配置文件,locale.conf,添加中文字体库等等等... 但都没有 ...

  4. Linux学习日记:第二天

    今天学习vi编辑命令: root@ubuntu:vi hello.java 使用到的命令: 插入命令: a 和 i:在当前光标前或后插入文本(A 和 I 分别在当前行行末或行首插入文本):  o 和  ...

  5. 因 URL 意外地以“/HelloWorld”结束,请求格式无法识别。

    web.config文件中的 <system.web> 节点下加入:<webServices>    <protocols>        <add name ...

  6. 洛谷 P1835 素数密度

    https://www.luogu.org/problemnew/show/P1835 对于40%,对每个数进行最大$O(\sqrt n)$的判断,因为n比较大所以超时. 想到线性筛,然而我们并不能筛 ...

  7. Unity基础-图形渲染

    图形渲染-Camera Camera下的Clear Flags:Skybox,Don't Clear,Depth only(深度),Solid Color(固定颜色) Culling Mask:渲染层 ...

  8. json转换为字典

    str---dict ata_dict=json.loads(data)

  9. 18/07/2017 R matrix

    矩阵:二维数组,元素拥有相同模式(数值型,字符型或者逻辑型) mymatrix <- matrix (vector, nrow_num_of_rows, ncol_num_of_columns, ...

  10. java做http接口

    问题描述 我要对外提供一个http接口给别人调用...但是我不知道用java怎么做这个接口.请大家详细给我讲讲.从开发到如何发布到服务器.谢谢了 解决方案 如果你这个很简单的话,而且数量也很少,建议直 ...