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
输入

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个数,这些数自由组合能不能凑出3600的倍数

题解:

我一开始想到的是前缀和,后来感觉dp最直接
dp[x]=1表示能组成x这个数
dp = 0表示组不了
cnt是中间数组,暂时存储本轮的数值
因为求能不能组成3600,可以用mod,3600的倍数mod后都是0,直接求dp[0]是否等于1
每读取一个a,就把a与之前所求的值进行相加存在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;
}

有个很玄学的地方我把读入n放在两个mem之前,数据就过了一半,放后面就ac了,不知道为什么
看来卡时间卡的太紧了(笑哭)

全部评论

相关推荐

03-10 11:23
门头沟学院 Java
点赞 评论 收藏
分享
昨天 13:24
已编辑
江西农业大学 后端工程师
最近或许大家都听说xxxx厂裁员,无论前端,后端,大数据,测试,运维,人人可危,&nbsp;“前端死了,后端也死了,JAVA崩盘了,你们这群搞大模型的真是码奸”这次AI真的会让我们无路可走吗????????太阳底下已经没有新鲜事了旧的生产力的消失,必然有新的生产力诞生马车夫消失&nbsp;→&nbsp;汽车司机、修车工、石油工业诞生,从业人数是马车夫的百倍手工纺织女工消失&nbsp;→&nbsp;纺织机械工程师、面料设计师诞生,纺织品产量提升百倍2007年苹果开放&nbsp;App&nbsp;Store,&quot;移动端开发者&quot;这个职业压根不存在。八年后,全球应用经济规模突破&nbsp;1000亿美元,凭空诞生了数百万开发者岗位。每一次&quot;这次真的完了...
二十岁的编程男神王大...:那这个时代是什么时代呢? 是全员agent的时代,是前端+AI,后端+AI的时代,AI已经融入了项目生命周期的的每一个角落,那我最近在做的东西举例,检查BUG时,我们会用codex,CC等工具的skill去check,效果好还能直接fix,测试的时候,apifox等工具已经有了AI落地的改造,CI/CD阶段,我们会根据hook去跑AI check脚本,就连不少中间件,也迎来了AI落地的改造,(AI网关,AI在MQ中的运用),都可以去了解下 另外记着,这些东西不是意义,工作只是谋生的一个手段,ai是让开发提效了,但是呢,原先一周的工作流程压缩到了两天内,同时低级的都裁员了,只有高级的去维护,你看似写的大义凛然,或许那天你也会成为你文章里面拒绝往前走的人,你才大二,面对技术有热情是对的
AI求职实录
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务