日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Music Problem

發(fā)布時(shí)間:2023/12/3 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Music Problem 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

文章目錄

    • 題目描述
    • 題意:
    • 題解:

傳送

時(shí)間限制:C/C++ 2秒,其他語言4秒 空間限制:C/C++ 131072K,其他語言262144K
64bit IO Format: %lld

題目描述

Listening to the music is relax, but for obsessive(強(qiáng)迫癥), 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
輸入

3 3 2000 1000 3000 3 2000 3000 1600 2 5400 1800

輸出

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個(gè)數(shù),這些數(shù)自由組合能不能湊出3600的倍數(shù)

題解:

我一開始想到的是前綴和,后來感覺dp最直接
dp[x]=1表示能組成x這個(gè)數(shù)
dp = 0表示組不了
cnt是中間數(shù)組,暫時(shí)存儲(chǔ)本輪的數(shù)值
因?yàn)榍竽懿荒芙M成3600,可以用mod,3600的倍數(shù)mod后都是0,直接求dp[0]是否等于1
每讀取一個(gè)a,就把a(bǔ)與之前所求的值進(jìn)行相加存在cnt里,然后再給dp[],cnt就是工具人

#include<bits/stdc++.h> #define mem(a) memset(a,0,sizeof(a))using namespace std; const int maxn=1e5+3; bool dp[maxn],cnt[maxn]; const int mod=3600; int main() {int t,n;scanf("%d",&t);while(t--){mem(dp);mem(cnt);scanf("%d",&n);for(int i=1;i<=n;i++){int a;cin>>a;a%=3600;if(!dp[0]){for(int j=0;j<3600;j++){if(dp[j]>0||j==0){cnt[(a+j)%3600]=1;}}for(int j=0;j<3600;j++){if(cnt[j])dp[j]=1;if(cnt[j]==1)cnt[j]=0;}// mem(cnt);}}if(!dp[0])cout<<"NO"<<endl;else cout<<"YES"<<endl;}return 0; }

有個(gè)很玄學(xué)的地方我把讀入n放在兩個(gè)mem之前,數(shù)據(jù)就過了一半,放后面就ac了,不知道為什么
看來卡時(shí)間卡的太緊了(笑哭)

總結(jié)

以上是生活随笔為你收集整理的Music Problem的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。