BestCoder Round #46

來源:互聯網
上載者:User

標籤:

1001 YJC tricks time

題目連結:1001

題意:給你時針和分針所成的角度,輸出現在的時間,以10秒為單位

思路:每10秒,分針走1度,時針走分針的1/12,我們可以根據時間來分別計算出分針和時針走的度數(分針可能走多圈),然後計算出二者的夾角(按題目的格式*12000)

我們可以得到一張時間對夾角的map表,對於輸入的夾角,去map中尋找是否存在對應的時間即可,除了0和06:00:00以外其他的夾角都對應兩個時間,這兩個時間互補。

code:

 1 #include <cstdio> 2 #include <map> 3 using namespace std; 4 const int MAXN = 43200; 5 const int MOD = 4320000; 6 map<int, int> mp; 7  8 void init() 9 {10     for (int i = 0; i < MAXN; i += 10)11     {12         int t1 = i * 1200 % MOD;13         int t2 = i * 100;14         int t = t1 - t2;15         if (t2 > t1) t = t2 - t1;16         if (t > 2160000) t = MOD - t;17         mp[t] = i;18     }19 }20 21 void solve(int n)22 {23     int hh = n / 3600;24     int mm = (n - hh * 3600) / 60;25     int ss = n - hh * 3600 - mm * 60;26     printf("%02d:%02d:%02d\n", hh, mm, ss);27 }28 29 int main()30 {31     init();32     int n;33     while (scanf("%d", &n) != EOF)34     {35         if (mp.count(n))36         {37             int t = mp[n];38             if (t != MAXN - t && t != 0) solve(MAXN - t);39             solve(t);40         }41     }42     return 0;43 }

 

BestCoder Round #46

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.