19暑假线性基A

A - XOR
XOR is a kind of bit operator, we define that as follow: for two binary base number A and B, let C=A XOR B, then for each bit of C, we can get its value by check the digit of corresponding position in A and B. And for each digit, 1 XOR 1 = 0, 1 XOR 0 = 1, 0 XOR 1 = 1, 0 XOR 0 = 0. And we simply write this operator as ^, like 3 ^ 1 = 2,4 ^ 3 = 7. XOR is an amazing operator and this is a question about XOR. We can choose several numbers and do XOR operatorion to them one by one, then we get another number. For example, if we choose 2,3 and 4, we can get 234=5. Now, you are given N numbers, and you can choose some of them(even a single number) to do XOR on them, and you can get many different numbers. Now I want you tell me which number is the K-th smallest number among them.
Input
First line of the input is a single integer T(T<=30), indicates there are T test cases.
For each test case, the first line is an integer N(1<=N<=10000), the number of numbers below. The second line contains N integers (each number is between 1 and 10^18). The third line is a number Q(1<=Q<=10000), the number of queries. The fourth line contains Q numbers(each number is between 1 and 10^18) K1,K2,…KQ.
Output
For each test case,first output Case #C: in a single line,C means the number of the test case which is from 1 to T. Then for each query, you should output a single line contains the Ki-th smallest number in them, if there are less than Ki different numbers, output -1.
Sample Input
2
2
1 2
4
1 2 3 4
3
1 2 3
5
1 2 3 4 5
Sample Output
Case #1:
1
2
3
-1
Case #2:
0
1
2
3
-1

Hint
If you choose a single number, the result you get is the number you choose.
Using long long instead of int because of the result may exceed 2^31-1.
类比与线性代数,线性基就是求出基向量,通过线性基,可得到这个空间所有数字
异或第k小板题

#include<bits/stdc++.h>
#define ll long long
#define MAXN 10005
using namespace std;
int t,n,q;
ll k,tmp;
struct L_B
{
	ll b[65],p[65];
	int cnt,flag;
	L_B()
	{
		memset(p,0,sizeof(p));
		memset(b,0,sizeof(b));
		cnt = flag = 0;
	}
	inline bool insert(ll x)
	{
		for(int i = 62;i >= 0;--i)
			if(x & (1ll <<i))
			{
				if(b[i])
					x ^= b[i];
				else
				{
					b[i] = x;
					return true;
				}
			}
		flag = 1;
		return false;
	}
	ll get_max()
	{
		ll ret = 0;
		for(int i = 62;i >= 0;--i)
			if((ret^b[i]) > ret)
				ret ^= b[i];
		return ret;
	}
	ll get_min()
	{
		if(flag)
			return 0;
		for(int i = 0;i <= 62;++i)
			if(b[i])
				return b[i];
		return 0;
	}
	inline void rebuild()
	{
		for(int i = 62;i >= 1;--i)
			if(b[i])
				for(int j = i-1;j >= 0;--j)
					if(b[i] & (1ll << j))
						b[i] ^= b[j];
		for(int i = 0;i <= 62;++i)
			if(b[i])
				p[cnt++] = b[i];
	}
	ll kth(ll k)
	{
		if(flag)
			--k;
		if(k == 0)
			return 0;
		ll ret = 0;
		if(k >= (1ll << cnt))
			return -1;
		for(int i = 0;i <= cnt-1;++i)
			if(k & (1ll << i))
				ret ^= p[i];
		return ret;
	}
};
L_B merge(const L_B &n1,const L_B &n2)
{
	L_B ret = n1;
	for(int i = 0;i <= 62;++i)
		if(n2.b[i])
			ret.insert(n2.b[i]);
	ret.flag = n1.flag | n1.flag;
	return ret;
}
int main()
{
	scanf("%d",&t);
	for(int cas = 1;cas <= t;++cas)
	{
		L_B lis;
		scanf("%d",&n);
		for(int i = 1;i <= n;++i)
		{
			scanf("%lld",&tmp);
			lis.insert(tmp);
		}
		
		scanf("%d",&q);
		lis.rebuild();
		printf("Case #%d:\n",cas);		
		while(q--)
		{
			scanf("%lld",&k);	
			printf("%lld\n",lis.kth(k));
		}
	}
}
【电动汽车充电站有序充电调度的分散式优化】基于蒙特卡诺和拉格朗日的电动汽车优化调度(分时电价调度)(Matlab代码实现)内容概要:本文介绍了基于蒙特卡洛和拉格朗日方法的电动汽车充电站有序充电调度优化方案,重点在于采用分散式优化策略应对分时电价机制下的充电需求管理。通过构建数学模型,结合不确定性因素如用户充电行为和电网负荷波动,利用蒙特卡洛模拟生成大量场景,并运用拉格朗日松弛法对复杂问题进行分解求解,从而实现全局最优或近似最优的充电调度计划。该方法有效降低了电网峰值负荷压力,提升了充电站运营效率与经济效益,同时兼顾用户充电便利性。 适合人群:具备一定电力系统、优化算法和Matlab编程基础的高校研究生、科研人员及从事智能电网、电动汽车相关领域的工程技术人员。 使用场景及目标:①应用于电动汽车充电站的日常运营管理,优化充电负荷分布;②服务于城市智能交通系统规划,提升电网与交通系统的协同水平;③作为学术研究案例,用于验证分散式优化算法在复杂能源系统中的有效性。 阅读建议:建议读者结合Matlab代码实现部分,深入理解蒙特卡洛模拟与拉格朗日松弛法的具体实施步骤,重点关注场景生成、约束处理与迭代收敛过程,以便在实际项目中灵活应用与改进。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值