Codeforces Round 871 (Div. 4) 题解

好久没打比赛了啊 qwq

A~C

skip

D

把能被 3 整除的数丢到一个队列里去 BFS,每次取队头把它分成两个,如果能被 3 整除继续入队。最后看给定的数有没有入过队。

E

直接 BFS,把每个块总和算出来求最大。

F

可以发现,图的点数 n=1+x+x×y。又易知,第二次多出来的点的度均 =1。设度为 1 的点数为 cnt,即 x×y=cnt。所以 x=ncnt1y=cnt/x

G

因为每塔的总层数不多(<2000),所以考虑枚举层,然后 O(1) 求单层内总和。

因为一层内倒的是连续的,所以尝试推一个柿子:

    a2+(a+1)2+(a+2)2+...+(a+m1)2

=m×a2+(2m2)×m2×a+(m1)×m×(2m1)6

然后考虑如何求每层的 am

记当前层倒下的右端点为 R,对应 m=Ra+1。从下往上做,有初始 a=n,R=n

n 所在层数可以预处理每层点数然后暴力找。对于第 i 层算完后,a,R 的变化有如下规律:

if(a==i*(i-1)/2+1) a-=i-1;
else a-=i;
if(R==i*(i+1)/2) R-=i;
else R-=i-1;

至于为什么,自己找几个数算算就好了。

赛后:官方题解直接递推啊,那没事了我是小丑。

血的教训:柿子不要抄错,不然可能对着正确的地方差半天错(

//If, one day, I finally manage to make my dreams a reality...
//I wonder, will you still be there by my side?
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false)
#define TIE cin.tie(0),cout.tie(0)
#define int long long
#define y1 cyy
#define fi first
#define se second
#define cnt1(x) __builtin_popcount(x)
#define mk make_pair
#define pb push_back
#define pii pair<int,int>
#define ls(x) (x<<1)
#define rs(x) (x<<1|1)
#define lbt(x) (x&(-x))
using namespace std;
int T,n,f[10005];
void solve(){
	cin>>n;
	int id;
	for(int i=1;i<=2000;i++){
		if(f[i]>=n){
			id=i;
			break;
		}
	}
	int a=n,R=n,ans=0,cnt=0,sum=0;
	for(int i=id;i>=1;i--){
		int m=R-a+1;
		ans+=m*a*a+((2ll*m-2)*m/2)*a+(m-1)*m*(2ll*m-1)/6;
		cnt++;
		if(a==i*(i-1)/2+1) a-=i-1;
		else a-=i;
		if(R==i*(i+1)/2) R-=i;
		else R-=i-1;
	}
	cout<<ans<<endl; 
}
signed main(){
	IOS;TIE;
	for(int i=1;f[i-1]<=1000000;i++){
		f[i]=f[i-1]+i;
	}
	cin>>T;
	while(T--) solve();
	return 0;
}
//m*a^2+((m*2-2)*m/2)a+(m-1)(m)(2m-1)/6 

H

考虑 DP

fi,j 表示前 i 个数,选取若干个与和 =j 的方案数。

有转移:

fi,j=fi,j+fi1,j

fi,j&ai=fi,j&ai+fi1,j

最后答案为 对于所有二进制下 1 的个数 =kifn,i

血的教训:div4不要去想什么乱七八糟的容斥

//If, one day, I finally manage to make my dreams a reality...
//I wonder, will you still be there by my side?
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false)
#define TIE cin.tie(0),cout.tie(0)
#define int long long
#define y1 cyy
#define fi first
#define se second
#define cnt1(x) __builtin_popcount(x)
#define mk make_pair
#define pb push_back
#define pii pair<int,int>
#define ls(x) (x<<1)
#define rs(x) (x<<1|1)
#define lbt(x) (x&(-x))
#define mod 1000000007
using namespace std;
int T,n,k,a[200005],f[200005][65],ans;
void solve(){
	cin>>n>>k;
	ans=0;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=n;i++){
		for(int j=0;j<64;j++) f[i][j]=0;
		f[i][a[i]]++;
		for(int j=0;j<64;j++){
			f[i][j&a[i]]+=f[i-1][j],f[i][j&a[i]]%=mod;
			f[i][j]+=f[i-1][j],f[i][j]%=mod;
		}
	}
	for(int s=0;s<(1<<6);s++){
		if(cnt1(s)==k) ans+=f[n][s],ans%=mod;
	}
	cout<<ans<<endl;
}
signed main(){
	IOS;TIE;
	cin>>T;
	while(T--) solve();
	return 0;
}
posted @   Binary_Lee  阅读(200)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 25岁的心里话
Title
点击右上角即可分享
微信分享提示