求助今天入门赛H题 求个Hack
  • 板块学术版
  • 楼主atom_yan
  • 当前回复1
  • 已保存回复1
  • 发布时间2023/8/11 21:53
  • 上次更新2023/11/3 04:22:33
查看原帖
求助今天入门赛H题 求个Hack
668765
atom_yan楼主2023/8/11 21:53
#include<bits/stdc++.h>
using namespace std;
template <typename T>inline void read(T& t){
	t=0; register char ch=getchar(); register int ffl=1;
	while(!('0'<=ch&&ch<='9')){if(ch=='-') ffl=-1;ch=getchar();}
	while(('0'<=ch&&ch<='9')){t=t*10+ch-'0'; ch=getchar();} t*=ffl;
}
template <typename T,typename... Args> inline void read(T& t, Args&... args){read(t);read(args...);}
template <typename T>inline void kread(T& t){
	t=0; register char ch=getchar(); register int cnt=0,fflag=0;
	while(!('0'<=ch&&ch<='9')){;ch=getchar();}
	while(('0'<=ch&&ch<='9')){
		if(!fflag){
			t=t*10+ch-'0',cnt++;
			if(cnt>15){
				fflag=1,t=LONG_LONG_MAX;
			}
		} 
		ch=getchar();
	}
}
typedef long long ll; 
const int N=1e6+5;
int t,n,a[N],p[N][4],fl[4];
ll k,sum;
int main(){
	read(t);
	while(t--){
		read(n),kread(k);
		memset(fl,0,sizeof(fl));
		sum=0;
		for(int i=1;i<=n;++i){
			p[i][0]=p[i][1]=p[i][2]=p[i][3]=0;
			read(a[i]);
			sum+=a[i];
			if(a[i]%7==0){
				p[i][2]++,fl[2]=max(fl[2],1);
				if(a[i]%49==0){
					p[i][2]++,fl[2]=2;
				}
			}
			if(a[i]%2==0)p[i][0]++,fl[0]=1;
			if(a[i]%3==0)p[i][1]++,fl[1]=1;
			if(a[i]%11==0)p[i][3]++,fl[3]=1;
		}
		if(n==1){
			if(a[1]>=k){
				puts("Yes");
				continue;
			}
			else{
				puts("No");
				continue;
			}
		}
		if(sum>=k){
			puts("Yes");
			continue;
		}
		if(!((fl[0]&&fl[2]&&fl[3])||(fl[1]&&fl[2]==1))){
			puts("No");
			continue;
		}
		int tmp=0;
		if(fl[0]&&fl[2]&&fl[3]){
			for(int i=1;i<=n;++i){
				tmp=max(tmp,(p[i][0]!=0)+(p[i][2]!=0)+(p[i][3]!=0));
			}
			if(tmp>=2){
				puts("Yes");
				continue;
			}
		}
		else{
			if(fl[2]==2){
				puts("Yes");
				continue;
			}
			int _sum=0;
			for(int i=1;i<=n;++i)
				_sum+=(p[i][2]!=0);
			if(_sum>=2){
				puts("Yes");
				continue;
			}
		}
		puts("No");
	}
	return 0;
}

基本思路是找有没有因子2,3,7,11,再根据这个来判断。感觉思路没错,但只a了第一个点,可能是小错误没找到。

2023/8/11 21:53
加载中...