杭电OJ 5387 Clock
2015-08-17 11:04
232 查看
Clock
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 529 Accepted Submission(s): 356
Problem Description
Give a time.(hh:mm:ss),you should answer the angle between any two of the minute.hour.second hand
Notice that the answer must be not more 180 and not less than 0
Input
There are T(1≤T≤104) test
cases
for each case,one line include the time
0≤hh<24,0≤mm<60,0≤ss<60
Output
for each case,output there real number like A/B.(A and B are coprime).if it's an integer then just print it.describe the angle between hour and minute,hour and second hand,minute and second hand.
Sample Input
4 00:00:00 06:00:00 12:54:55 04:40:00
Sample Output
0 0 0 180 180 0 1391/24 1379/24 1/2 100 140 120 Hint每行输出数据末尾均应带有空格此题首先要弄清分 秒 时三者之间的关系。然后我是计算它们三者到12点钟方向的角度,它们三者角度差的绝对值就是它们之间的角度。当然,由于题目特殊要求,记录数据我是用分子分母两个部分记录。同时求最大公约数的函数用递归貌似会出现“爆栈”的问题,所以没用递归实现。#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<cmath> #include<algorithm> #include<stack> #include<queue> #include<vector> using namespace std; long long T; long long H,M,S; long long SM,SZ,MM,MZ,HM,HZ; char c,s[10]; long long t,mom,son; long long gcd(long long a,long long b) { long long tt; if(a<b) swap(a,b); //return b==0?a:gcd(b,a%b); while(b) { tt=a; a=b; b=tt%b; } return a; } int main() { while(cin>>T) { while(T--) { cin>>s; H=(*s-'0')*10 + s[1]-'0'; M=(s[3]-'0')*10 + s[4]-'0'; S=(s[6]-'0')*10 + s[7]-'0'; if(H>=12) H-=12; //=12也要减哦 SZ=S*6; SM=1; //cout<<SM<<" "<<SZ<<endl;/////// //t=gcd(10,S); //MZ=M*6; MZ=60*M+S; MM=10; //cout<<MM<<" "<<MZ<<endl;/////// t=gcd(MZ,MM); MM/=t; MZ/=t; //HZ=H*30; HM=120; HZ=3600*H + 60*M + S; //cout<<HM<<" "<<HZ<<endl;/////// t=gcd(HM,HZ); HZ/=t; HM/=t; mom = HM*MM; son = abs(HZ*MM - MZ*HM); if(son>180*mom) {son=360*mom - son;} t=gcd(son,mom); if(son%mom == 0) cout<<son/mom<<" "; else cout<<(son)/t<<"/"<<(mom)/t<<" "; mom = HM*SM; son = abs(HZ*SM - SZ*HM); if(son>180*mom) {son=360*mom - son;} t=gcd(son,mom); if(son%mom == 0) cout<<son/mom<<" "; else cout<<(son)/t<<"/"<<(mom)/t<<" "; mom = MM*SM; son = abs(MZ*SM - SZ*MM); if(son>180*mom) {son=360*mom - son;} t=gcd(son,mom); if(son%mom == 0) cout<<son/mom<<" "; else cout<<(son)/t<<"/"<<(mom)/t<<" "; // cout<<endl; } } return 0; }
相关文章推荐
- 升级ZC451 codebase遇到的问题以及解决方法
- 中介者模式
- 质因数分解及算法实现
- MySQL-Linux安装
- matlab 画图
- ijkplayer阅读笔记06-音频流程
- vijos - P1319数列 (二进制 + 找规律 + python)
- string get_telno(string &userid) 和 string get_telno(string userid) 有什么区别
- JAVA文件扫描(递归)
- 剑指offer——面试题24:二叉搜索树的后续遍历序列
- [LeetCode]Sliding Window Maximum
- 用VS发布的程序,如何让快捷方式指向exe而不是msi文件
- ckeditor换kama皮肤
- hash + bsgs模板
- POJ3667 Hotel
- F
- Python Web Scraper - Simple Url Request
- writing a usb driver(在国外的网站上复制下来的)
- Android学习系列--App调试内存泄露之Context篇(上)
- 戦後70年に問う―個人を尊重する国の約束