2023年多校联训NOIP层测试2

挂了好多分,yyy。


T1 斐波那契树

题目

image

思路

比原题要简单一点。只用判是否存在。

题解做法:

可以先把白色边权看成1,黑色边权看成0,求最小生成树和最大生成树,判断这两个值之间是否存在一
个斐波那契数。可以证明这中间的值都是可以出现的(参考求恰好k条白边的思路,BZOJ2654)。

我的做法:
找到最小生成树和最大生成树的值。

看它们是否在两个斐波那契数之间,是就存在,不在否之。

code

点击查看代码
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+10;
int T,n,m,fa[N],f[30];
struct node{int from,to,w;}e[N];
inline bool cmp1(node x,node y){
	return x.w<y.w;
} 
inline bool cmp2(node x,node y){
	return x.w>y.w;
}
inline int ff(int x){
	if(x!=fa[x])
		fa[x]=ff(fa[x]);
	return fa[x];
}
inline bool kru(int &ans){
	int cnt=0;
	for(int i=1;i<=n;++i) fa[i]=i;
	for(int i=1;i<=m;++i){
		if(cnt==n-1) break;
		int x=ff(e[i].from),y=ff(e[i].to);
		if(x!=y){
			fa[x]=y;
			ans+=e[i].w;
			++cnt; 
		}
	}
	return cnt==n-1;
}
signed main(void){
	scanf("%lld",&T);
	f[1]=f[2]=1;
	for(int i=3;i<=30;++i) f[i]=f[i-1]+f[i-2]; 
	while(T--){
		int minn=0,maxx=0;
		memset(e,0,sizeof e);
		scanf("%lld%lld",&n,&m);
		for(int x,y,z,i=1;i<=m;++i){
			scanf("%lld%lld%lld",&e[i].from,&e[i].to,&e[i].w);
		}
		sort(e+1,e+m+1,cmp1);
		if(!kru(minn)){
			printf("NO\n");
			continue;
		}
		sort(e+1,e+m+1,cmp2);
		if(!kru(maxx)){
			printf("NO\n");
			continue; 
		}
		for(int i=1;;++i){
			if(f[i]>=minn&&f[i]<=maxx){
				printf("YES\n");
				break;
			}
			else if(f[i]>maxx){
				printf("NO\n");
				break;
			}
		}
	}
	return 0;
} 

T2 期末考试

image

思路

题解思路:

meet in the middle。

枚举前 5 5 5 道题的答案,计算对于 n n n 次回答每个最终的得分并将这 n n n 个数哈希起来。再
枚举后面 5 5 5 道题的答案,计算 n n n 次回答的得分,找到前 5 5 5 次回答应该获得的 n n n 个分数出现了多少次,统计答
案即可。

我的思路:
可能是数据点太水了(骗了数据, n n n 只有 1 1 1 10 10 10 两种情况)。所以考虑直接爆搜即可。

code

点击查看代码
#include<bits/stdc++.h>
using namespace std;
const int N=2e4+1;
const char d[]={'A','B','C','D'};
int T,sum,n,cnt,a[N];
char s[N][11],ss[N];
inline void dfs(int x){
	if(x>=10){
		for(int i=1;i<=n;++i){
			cnt=0;
			for(int j=1;j<=10;++j){
				if(ss[j-1]==s[i][j]) ++cnt;
			}
			if(cnt!=a[i]) return ;
		}
		++sum;return ;
	}
	for(int i=0;i<4;++i){
		ss[x]=d[i];
		dfs(x+1);
	}
}
signed main(void){
	scanf("%d",&T);
	while(T--){
		sum=0;
		int cnt=0,ans=1;
		scanf("%d",&n);
		for(int i=1;i<=n;++i){
			cin>>(s[i]+1);
			scanf("%d",&a[i]);
			a[i]/=10;
		}
		dfs(0);
		printf("%d\n",sum);
	}
	
}

T3 麻烦的工作

题目

image

思路

image
(T3挂掉了,代码没调出来。)

T4 小X的Galgame

题目

image

思路

image
(T4也挂掉了,代码没调出来。)

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值