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. Classes and metaclasses

    http://www.sealiesoftware.com/blog/archive/2009/04/14/objc_explain_Classes_and_metaclasses.html Obje ...

  2. Java的引用StrongReference、 SoftReference、 WeakReference 、PhantomReference

    1. Strong Reference StrongReference 是 Java 的默认引用实现,  它会尽可能长时间的存活于 JVM 内, 当没有任何对象指向它时 GC 执行后将会被回收 @Te ...

  3. Bootstrap历练实例:默认的进度条

    <!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...

  4. Java第11次作业:什么是继承?继承的好处?什么是覆写?super()?构造代码块?子父类初始化顺序? 抽象类能用final声明吗?final关键字声明类 方法 变量以及全局常量?抽象类的构造方法?

    什么是继承? 继承是以父类为基础,子类可以增加新的数据或新的功能.子类不能选择性地继承父类.这种技术使得复用以前的代码非常容易. JAVA不支持多继承,单继承使JAVA的继承关系很简单,一个类只能有一 ...

  5. cocos2dx 3.x lua 网络加载并且保存资源(unix、linux)

    #ifndef __DazzleParkour__TextLoader__ #define __DazzleParkour__TextLoader__ #include <stdio.h> ...

  6. vc文件操作汇总—支持wince

    一.判断文件及文件夹是否存在 // 判断文件是否存在 BOOL IsFileExist(const CString& csFile) { DWORD dwAttrib = GetFileAtt ...

  7. codis 配置

    #修改dashboard.toml: coordinator_name = "zookeeper" coordinator_addr = "192.168.56.101: ...

  8. FTP服务-实现vsftpd虚拟用户

    前几篇介绍了基础,这篇将具体实现几个案例 实现基于文件验证的vsftpd虚拟用户,每个用户独立一个文件夹 1.创建用户数据库文件 vim /etc/vsftpd/vusers.txt qq cento ...

  9. paper:synthesizable finit state machine design techniques using the new systemverilog 3.0 enhancements之onehot coding styles(index-parameter style with registered outputs)

    case语句中,对于state/next 矢量仅仅做了1-bit比较. parameter 值不是表示FSM的状态编码,而是表示state/next变量的索引.

  10. 18/07/2017 R matrix

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