HDOJ 2076 夹角有多大(题目已修改,注意读题)

来源:互联网 发布:西澳大学 知乎 编辑:程序博客网 时间:2024/05/21 21:45

题意:给出一个时间,求在石英钟上显示这个时间,时针和分针之间的角度,并对角度进行取整

链接:http://acm.hdu.edu.cn/showproblem.php?pid=2076

思路:全部转化成秒,用过秒的比例转化成角度,在进行计算

注意点:所求夹角可能超过180度


以下为AC代码:

Run IDSubmit TimeJudge StatusPro.IDExe.TimeExe.MemoryCode Len.LanguageAuthor126838392015-01-11 23:57:00Accepted207615MS1252K1256 BG++luminous11

#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <vector>#include <deque>#include <list>#include <cctype>#include <algorithm>#include <climits>#include <queue>#include <stack>#include <cmath>#include <map>#include <set>#include <iomanip>#include <cstdlib>#include <ctime>#define ll long long#define ull unsigned long long#define all(x) (x).begin(), (x).end()#define clr(a, v) memset( a , v , sizeof(a) )#define pb push_back#define mp make_pair#define read(f) freopen(f, "r", stdin)#define write(f) freopen(f, "w", stdout)using namespace std;const double pi = acos(-1);int main(){    ios::sync_with_stdio( false );    int n;    cin >> n;    while (n -- ){        int a, b, c;        cin >> a >> b >> c;        if ( a > 12 ) a -= 12;        double ang_1 = ( b * 60.0 + c ) / 10.0;        double ang_2 = ( a * 3600.0 + b * 60.0 + c ) / ( 10.0 * 12.0 );        double ans = 0;        if ( ang_1 > ang_2 ){            ans = ang_1 - ang_2;        }        else{            ans = ang_2 - ang_1;        }        if ( ans > 180 ) ans = 360.0 - ans;        cout << fixed << setprecision (0) << ans - 0.5 << endl;    }    return 0;}


0 0
原创粉丝点击