UvaLive 6664 Clock Hands
链接:http://vjudge.net/problem/viewProblem.action?id=49409
题意:给一个奇怪的能够记录N小时内时间的表(生活中的表是12小时计时的)。
而且给出一个当前时间,求下一个出现的秒针恰巧在时针和分针中间的情况的时间,输出整数的小时和分钟还实用分数表示的秒。
思路:
首先计算时针分针秒针当前转动角度。记整个表盘总角度为1.
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvb29vb29vb29l/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="" />
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvb29vb29vb29l/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="" />
设经过了ss时间后,出现题目中要求的情况。
则可列出式子:
将上述带入,化简得:
我们要取的是k=1时候的情况。假设k=1时三个针恰好重叠,那就取k=2时,从小到大向上取。当中的小问题就在于怎样分数表示秒。
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<cstdlib>
#include<queue>
#include<stack>
#include<vector>
#include<ctype.h>
#include<algorithm>
#include<string>
#define PI acos(-1.0)
#define maxn 10005
#define INF 0x7fffffff
typedef long long ll;
using namespace std;
int gcd(int x,int y)
{
return y?
gcd(y,x%y):x;
}
int main()
{
int H,h,m,s,ans_h,ans_m,ans_s;
while(scanf("%d%d%d%d",&H,&h,&m,&s)&&!(!H&&!h&&!m&&!s))
{
int hh=3600*h+60*m+s;
int mm=60*m*H+s*H;
int ss=60*s*H;
int K=3600*H;
int cmp=mm+hh-ss*2;
cmp=(cmp%K+K)%K;
int aa=119*H-1;
while(1)
{
int a=aa;
int c=cmp;
int t=gcd(a,c);
a/=t;c/=t;
ans_h=(h+(m+(a*s+c)/(a*60))/60)%H;
ans_m=(m+(a*s+c)/(a*60))%60;
ans_s=(a*s+c)%(a*60);
if((3600*ans_h+60*ans_m)*a+ans_s!=60*ans_m*a*H+ans_s*H)
{
printf("%d %d %d %d\n",ans_h,ans_m,ans_s,a);
break;
}
cmp+=K;
}
}
return 0;
}
UvaLive 6664 Clock Hands的更多相关文章
- UVALive - 6269 Digital Clock 模拟
UVALive - 6269 Digital Clock 题意:时钟坏了,给你一段连续的时间,问你现在可能的时间是多少. 思路:直接模拟,他妈的居然这场就跪在了这题,卧槽,他妈的就在111行,居然多打 ...
- UVALive 6269 Digital Clock --枚举,模拟
题意:说不清楚,自己看吧,太恶心. 这题真是SB了,当时看了一下以为乱搞就好了,于是开始动手拍,结果拍了好几个小时都没拍出来,而且越想越想不通,直接把自己绕进去了,结果gg了. 总结:甭管什么题,想清 ...
- POJ 1087 A Plug for UNIX / HDU 1526 A Plug for UNIX / ZOJ 1157 A Plug for UNIX / UVA 753 A Plug for UNIX / UVAlive 5418 A Plug for UNIX / SCU 1671 A Plug for UNIX (网络流)
POJ 1087 A Plug for UNIX / HDU 1526 A Plug for UNIX / ZOJ 1157 A Plug for UNIX / UVA 753 A Plug for ...
- 修改Linux系统日期与时间date clock
先设置日期 date -s 20080103 再设置时间 date -s 18:24:30 为了永久生效,需要将修改的时间写入CMOS. 查看CMOS的时间: #clock -r 将当前系统时间写到C ...
- 操作系统页面置换算法(opt,lru,fifo,clock)实现
选择调出页面的算法就称为页面置换算法.好的页面置换算法应有较低的页面更换频率,也就是说,应将以后不会再访问或者以后较长时间内不会再访问的页面先调出. 常见的置换算法有以下四种(以下来自操作系统课本). ...
- Cesium应用篇:3控件(1)Clock
创建 跟Clock相关的主要有Animation控件和Timeline控件,通常两者会放在一起使用. 在Cesium中,Viewer默认开启这两个控件,如果你想要不显示控件,可以在Viewer初始化中 ...
- UVALive - 4108 SKYLINE[线段树]
UVALive - 4108 SKYLINE Time Limit: 3000MS 64bit IO Format: %lld & %llu Submit Status uDebug ...
- UVALive - 3942 Remember the Word[树状数组]
UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...
- UVALive - 3942 Remember the Word[Trie DP]
UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...
随机推荐
- chalk插件 使终端输出的字带颜色
1.使终端输出红色字体: const chalk = require('chalk'); console.log(chalk.red('this is red!') 这时运行终端,打印的this is ...
- Spring Boot 的各种start
新建一个springBoot项目时,你会选择很多依赖,在项目中的build.gradle中你会看见各种start,例如下边的代码: 今天就在这里列举一下各种start: 1.spring-boot-s ...
- python导入包失败ModuleNotFoundError: No module named 'matplotlib.pyplot'; 'matplotlib' is not a package
最近在看 python,在使用matplotlib进行绘图时,提示:ModuleNotFoundError: No module named 'matplotlib.pyplot'; 'matplot ...
- 2019hdu多校 Minimal Power of Prime
题目链接:Click here 题目大意:求一个数分解质因数后的最小幂指数 Solution: 首先,我们肯定是不能直接暴力求解的 我们先考虑筛出1e4范围以内的所有质数,把x所有这个范围内的质因子筛 ...
- cmake尝试检测GCC版本报错
本人尝试编译指定commit版本的MRPT库,报错如下, CMake Error at cmakemodules/script_detect_gcc.cmake: (LIST): list GET g ...
- cvpr 2019 workshop&oral session
1. Verification and Certification of Neural Networks神经网络的验证与认证 2. Automated Analysis of Marine Video ...
- 【技术分享:python 应用之二】解锁用 VSCode 写 python 的正确姿势
之前一直用 notepad++ 作为编辑器,偶然发现了 VScode 便被它的颜值吸引.用过之后发现它启动快速,插件丰富,下载安装后几乎不用怎么配置就可以直接使用,而且还支持 markdown.当然, ...
- Python For Mac 开发环境安装 以及问题记录
Python For Mac 开发环境安装记录 把自己安装的过程记录一下,亲测可用 1.Python3环境安装(转载http://www.cnblogs.com/meng1314-shuai/p/90 ...
- java中的char,short,int,long占几个字节
1:“字节”是byte,“位”是bit : 2: 1 byte = 8 bit : char 在java中是2个字节.java采用unicode,2个字节(16位)来表示一个字符. short 2个字 ...
- sso单点登录原理详解
sso单点登录原理详解 01 单系统登录机制 1.http无状态协议 web应用采用browser/server架构,http作为通信协议.http是无状态协议,浏览器的每一次请求,服务 ...