zoukankan      html  css  js  c++  java
  • HDU 5705 Clock (精度控制,暴力)

    题意:给定一个开始时间和一个角度,问你下一个时刻时针和分针形成这个角度是几点。

    析:反正数量很小,就可以考虑暴力了,从第一秒开始暴力,直到那个角度即可,不会超时的,数目很少,不过要注意精度。

    代码如下:

    #include <cstdio>
    #include <string>
    #include <cstdlib>
    #include <cmath>
    #include <iostream>
    #include <cstring>
    #include <set>
    #include <queue>
    #include <algorithm>
    #include <vector>
    #include <map>
    using namespace std ;
    typedef long long LL;
    typedef pair<int, int> P;
    const int INF = 0x3f3f3f3f;
    const double inf = 0x3f3f3f3f3f3f3f;
    const double eps = 1e-8;
    const int mod = 360*120;
    const int maxn = 2000 + 5;
    const int dr[] = {0, 0, -1, 1};
    const int dc[] = {-1, 1, 0, 0};
    int n, m;
    inline bool is_in(int r, int c){
        return r >= 0 && r < n && c < m && c >= 0;
    }
    
    int main(){
        int h, m, s, t, kase = 0;
        while(scanf("%d:%d:%d", &h, &m, &s) == 3){
            scanf("%d", &t);
            t *= 120;
            int sum = h * 3600 + m * 60 + s;
            int hh = sum % mod;
            int mm = (sum * 12) % mod;
            int ans = 0;
    
            while(true){
                hh = (hh + 1) % mod;
                mm = (mm + 12) % mod;
                ++ans;
                if(abs(abs(mm-hh) - t) <= 10)  break;
            }
    
            int sss = (ans + s) % 60;
            int mmm = ((ans+s) / 60 + m) % 60;
            int hhh = (((ans+s) / 60 + m) / 60 + h) % 12;
            printf("Case #%d: %02d:%02d:%02d
    ", ++kase, hhh, mmm, sss);
        }
        return 0;
    }
    
  • 相关阅读:
    48. Rotate Image
    47. Permutations II
    46. Permutations
    45. Jump Game II
    44. Wildcard Matching
    43. Multiply Strings
    42. Trapping Rain Water
    41. First Missing Positive
    40. Combination Sum II
    39. Combination Sum
  • 原文地址:https://www.cnblogs.com/dwtfukgv/p/5719410.html
Copyright © 2011-2022 走看看