跳到正文

xianxi

1021348

恐惧是生物的本能,勇气是人类的赞歌

在洛谷打开
资料、奖项与版本

资料

编号
1021348
抓取

chinese chess

题解站

题解改版机

ss传送门

OIWIKI

my school

NOI大纲分析

bitset用法详解 didiao233

csp初赛技巧

向量叉积

C++
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
int n,col,q;
struct node{
	bitset<32>tag;
	bitset<32>condition;
}tree[N<<2];
int ls(int d){return (d<<1);}
int rs(int d){return ((d<<1)|1);}
void push_up(int d)
{
	tree[d].condition=(tree[ls(d)].condition|tree[rs(d)].condition);
	return ;
}
void push_down(int d)
{
	if(tree[d].tag)
	{
		tree[ls(d)].condition=tree[ls(d)].tag=tree[d].tag;
		tree[rs(d)].condition=tree[rs(d)].tag=tree[d].tag;
		tree[d].tag.reset();
	}
	return ;
}
void build(int l,int r,int d)
{
	if(l==r)
	{
		tree[d].condition.set(1);
		return ;
	}
	int mid=(l+r)>>1;
	build(l,mid,ls(d));
	build(mid+1,r,rs(d));
	push_up(d);
	return ;
}
void change(int ,ql,int qr,int l,int r,int d)
{
	
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>col>>q;
    build(1,n,1);
    while(q--)
    {
    	
	}
	return 0;
}
C++
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1000005;
int n,m,t,k,s[N],x,y,a[N],b[N],ans,tt[N];
void init()
{
	for(int i=1;i<=n;++i)s[i]=i;
	return ;
}
int find_s(int x)
{
	if(s[x]==x)return x;
	else return s[x]=find_s(s[x]);
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m>>x>>y;
	cin>>t>>k;
	init();
	for(int i=1;i<=m;++i)
	{
		cin>>a[i]>>b[i];
	}
	for(int i=1;i<=m;++i)
	{
		cin>>tt[i];
		tt[i+m]=tt[i];
	}
	int l,r,u;
	for(int i=1;i<=2*m;++i)
	{
	//	l=find_s(a[tt[i]]),r=find_s(b[tt[i]]);/give @p minecraft:diamond_sword[minecraft:enchantments={sharpness:255}] 1
		u=find_s(x);
		ans+=t;
		if(l!=u&&r!=u)continue;
		if(l!=r)
		{
			s[l]=r;
		}
		if(find_s(x)==find_s(y))
		{
			ans=ans-t+k;
			break;
		}
	}
	cout<<ans;
	return 0;
}
C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1000005;
int n,m,t,k,s[N],x,y,a[N],b[N],ans,tt[N];
void init()
{
	for(int i=1;i<=n;++i)s[i]=i;
	return ;
}
int find_s(int x)
{
	if(s[x]==x)return x;
	else return s[x]=find_s(s[x]);
}
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m>>x>>y;
	cin>>t>>k;
	init();
	for(int i=1;i<=m;++i)
	{
		cin>>a[i]>>b[i];
	}
	for(int i=1;i<=m;++i)
	{
		cin>>tt[i];
		tt[i+m]=tt[i];
	}
	int l,r,u;
	for(int i=1;i<=2*m;++i)
	{
		l=find_s(a[tt[i]]),r=find_s(b[tt[i]]);
		u=find_s(x);
		ans+=t;
		if(l!=u&&r!=u)continue;
		if(l!=r)
		{
			s[l]=r;
		}
		if(find_s(x)==find_s(y))
		{
			ans=ans-t+k;
			break;
		}
	}
	cout<<ans;
	return 0;
}
C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1000005;
int n,m,t,k,s[N],x,y,a[N],b[N],ans,tt[N];
map<int,map<int,int> >mp;
map<int,int>mp1;
signed main()
{
	freopen("1.in","w",stdout);
	srand(time(0));
	n=rand()%1000000;
	m=rand()%1000000;
	k=rand()%1000000;
	while(t<k)t=rand()%1000000;
	cout<<n<<" "<<m<<" "<<t<<" "<<k<<"\n";
	x=(rand()%n)+1;
	while(x==y)y=(rand()%n)+1;
	cout<<x<<" "<<y<<"\n";
	for(int i=1;i<=m;++i)
	{
		int ss=0,tt=0;
		while((mp[ss][tt]||mp[tt][ss])||ss==tt)
		{
			ss=(rand()%n)+1;
			while(ss!=tt)tt=(rand()%n)+1;
		}
		mp[ss][tt]=1;
		mp[tt][ss]=1;
		cout<<ss<<" "<<tt<<"\n";
	}
	for(int i=1;i<=m;++i)
	{
		int tu;
		while(mp1[tu])tu=(rand()%m)+1;
		mp1[tu]=1;
		cout<<tu<<"\n";
	}
	return 0;
}
共 1 篇
  1. 题解

    题解:P12316 [蓝桥杯 2024 国 C] 循环位运算

    本文介绍了一道关于循环位运算求最大和的算法题解,主要内容如下: 问题描述:给定 n 个 32 位二进制数,总共可进行 m 次循环左移操作,求操作后 n 个数的最大总和。 解题思路:采用动态规划(DP)。 预处理:计算每个数进行 0 到 m 次移位后的结果,存入数组 num_i,j。 状态定义:dp_i,j 表示前 i 个数总共操作 j 次所能获得的最大和。 状态转移:通过枚举第 i 个数分配的操作次数 k,利用公式 dp_i,j=max(dp_i,j, dp_i-1,j-k+num_i,k) 更新状态。 实现细节:代码包含预处理、DP 计算及结果输出三部分。特别强调在预处理移位时需使用 long long 类型,以避免 int 类型因左移导致的溢出错误。

    4 赞