汕頭食品駿域網(wǎng)站建設(shè)廣州seo
CF1714A Everyone Loves to Sleep 題解
- 題目
- 鏈接
- 字面描述
- 題面翻譯
- 題目描述
- 輸入格式
- 輸出格式
- 樣例解釋
- 題目描述
- 輸入格式
- 輸出格式
- 樣例 #1
- 樣例輸入 #1
- 樣例輸出 #1
- 代碼實(shí)現(xiàn)
題目
鏈接
https://www.luogu.com.cn/problem/CF1714A
字面描述
題面翻譯
題目描述
Vlad和其他人一樣,非常喜歡睡覺。
Vlad每天都要做 nnn 件事,每件事在特定時(shí)間。對于這些事情中的每一件,他都定了一個(gè)鬧鐘,其中第 iii 個(gè)在 hih_ihi? 時(shí) mim_imi? 分被觸發(fā)(0≤hi<24,0≤mi<60)0\le h_i<24,0\le m_i<60)0≤hi?<24,0≤mi?<60)。
Vlad使用24小時(shí)時(shí)間格式,所以12:59之后是13:00,23:59后是00:00。
Vlad在H時(shí)M分睡覺(0≤H<24,0≤M<600 \le H < 24, 0 \le M < 600≤H<24,0≤M<60)。
他要你回答:在下一個(gè)鬧鐘響之前,他能睡多久。
如果在他上床睡覺的時(shí)候有任何鬧鐘響起,那么他將睡0小時(shí)0分鐘。
輸入格式
輸入數(shù)據(jù)的第一行包含一個(gè)整數(shù) ttt (1≤t≤1001 \le t \le 1001≤t≤100) — 測試中測試用例的數(shù)量。
每組測試用例的第一行包含三個(gè)整數(shù) nnn , HHH 和 MMM ($ 1 \le n \le 10, 0 \le H < 24, 0 \le M < 60$) — 鬧鐘的數(shù)量和Vlad上床睡覺的時(shí)間。
以下 nnn 行各包含兩個(gè)數(shù)字 hih_ihi? 和 mim_imi? ( 0≤hi<24,0≤mi<600 \le h_i < 24, 0 \le m_i < 600≤hi?<24,0≤mi?<60) — 每個(gè)鬧鐘響的時(shí)間。兩個(gè)或多個(gè)鬧鐘可以同時(shí)響起。描述時(shí)間的數(shù)字不包含前導(dǎo)零。
輸出格式
輸出 ttt 行,每行都包含相應(yīng)測試用例的答案。
作為答案,輸出兩個(gè)數(shù)字 - Vlad將分別睡覺的小時(shí)數(shù)和分鐘數(shù)。如果在他上床睡覺的時(shí)候有任何鬧鐘響起,答案將是 000\ 00?0。
樣例解釋
對于第一個(gè)測試用例,Vlad上床后第一個(gè)響的鬧鐘是8:00的。
對于第二個(gè)測試用例,Vlad上床時(shí)有鬧鐘響起。
對于第三個(gè)測試用例,Vlad上床后第一個(gè)響的鬧鐘是第二天10:30的。
題目描述
Vlad, like everyone else, loves to sleep very much.
Every day Vlad has to do $ n $ things, each at a certain time. For each of these things, he has an alarm clock set, the $ i $ -th of them is triggered on $ h_i $ hours $ m_i $ minutes every day ( $ 0 \le h_i < 24, 0 \le m_i < 60 $ ). Vlad uses the $ 24 $ -hour time format, so after $ h=12, m=59 $ comes $ h=13, m=0 $ and after $ h=23, m=59 $ comes $ h=0, m=0 $ .
This time Vlad went to bed at $ H $ hours $ M $ minutes ( $ 0 \le H < 24, 0 \le M < 60 $ ) and asks you to answer: how much he will be able to sleep until the next alarm clock.
If any alarm clock rings at the time when he went to bed, then he will sleep for a period of time of length $ 0 $ .
輸入格式
The first line of input data contains an integer $ t $ ( $ 1 \le t \le 100 $ ) — the number of test cases in the test.
The first line of the case contains three integers $ n $ , $ H $ and $ M $ ( $ 1 \le n \le 10, 0 \le H < 24, 0 \le M < 60 $ ) — the number of alarms and the time Vlad went to bed.
The following $ n $ lines contain two numbers each $ h_i $ and $ m_i $ ( $ 0 \le h_i < 24, 0 \le m_i < 60 $ ) — the time of the $ i $ alarm. It is acceptable that two or more alarms will trigger at the same time.
Numbers describing time do not contain leading zeros.
輸出格式
Output $ t $ lines, each containing the answer to the corresponding test case. As an answer, output two numbers — the number of hours and minutes that Vlad will sleep, respectively. If any alarm clock rings at the time when he went to bed, the answer will be 0 0.
樣例 #1
樣例輸入 #1
3
1 6 13
8 0
3 6 0
12 30
14 45
6 0
2 23 35
20 15
10 30
樣例輸出 #1
1 47
0 0
10 55
代碼實(shí)現(xiàn)
一道大模擬題;
最壞時(shí)間復(fù)雜度為:O(t?n?1440)≈1e6O(t·n·1440) ≈ 1e6O(t?n?1440)≈1e6
#include<bits/stdc++.h>
using namespace std;const int maxn=100+10;
int t,n,h,m,ansh,ansm;
int a[maxn][2];
int main(){scanf("%d",&t);while(t--){scanf("%d%d%d",&n,&h,&m);for(int i=1;i<=n;i++)scanf("%d%d",&a[i][0],&a[i][1]);ansh=ansm=0; while(1){bool flag=false;for(int i=1;i<=n;i++){if(h==a[i][0]&&m==a[i][1]){printf("%d %d\n",ansh,ansm);flag=true;break;}}if(flag)break;++m;if(m==60)m=0,++h;if(h==24)h=0;++ansm;if(ansm==60)ansm=0,++ansh;if(ansh==24)ansh=0;}}return 0;
}