Music Problem
文章目錄
- 題目描述
- 題意:
- 題解:
傳送
時間限制:C/C++ 2秒,其他語言4秒 空間限制:C/C++ 131072K,其他語言262144K
64bit IO Format: %lld
題目描述
Listening to the music is relax, but for obsessive(強迫癥), it may be
unbearable. HH is an obsessive, he only start to listen to music at
12:00:00, and he will never stop unless the song he is listening ends
at integral points (both minute and second are 0 ), that is, he can
stop listen at 13:00:00 or 14:00:00,but he can’t stop at 13:01:03 or
13:01:00, since 13:01:03 and 13:01:00 are not an integer hour time.
Now give you the length of some songs, tell HH whether it’s possible
to choose some songs so he can stop listen at an integral point, or
tell him it’s impossible. Every song can be chosen at most once.
輸入描述:
The first line contains an positive integer T(1≤T≤60), represents
there are T test cases. For each test case: The first line
contains an integer n(1≤n≤105), indicating there are n songs. The
second line contains n integers a1,a2…an (1≤ai≤109 ), the ith integer
ai indicates the ith song lasts ai seconds.
輸出描述:
For each test case, output one line “YES” (without quotes) if HH is
possible to stop listen at an integral point, and “NO” (without
quotes) otherwise.
示例1
輸入
輸出
NO YES YES說明
In the first example it’s impossible to stop at an integral point.
In the second example if we choose the first and the third songs, they cost 3600 seconds in total, so HH can stop at 13:00:00
In the third example if we choose the first and the second songs, they cost 7200 seconds in total, so HH can stop at 14:00:00
題意:
給你n個數,這些數自由組合能不能湊出3600的倍數
題解:
我一開始想到的是前綴和,后來感覺dp最直接
dp[x]=1表示能組成x這個數
dp = 0表示組不了
cnt是中間數組,暫時存儲本輪的數值
因為求能不能組成3600,可以用mod,3600的倍數mod后都是0,直接求dp[0]是否等于1
每讀取一個a,就把a與之前所求的值進行相加存在cnt里,然后再給dp[],cnt就是工具人
有個很玄學的地方我把讀入n放在兩個mem之前,數據就過了一半,放后面就ac了,不知道為什么
看來卡時間卡的太緊了(笑哭)
總結
以上是生活随笔為你收集整理的Music Problem的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Chrome中的GPU加速合成
- 下一篇: ChatGPT 中文调教指南