2460: [BeiJing2011]元素

链接

分析:

  贪心的想:首先按权值排序,然后从大到小依次放,能放则放。然后用线性基维护是否合法。

代码:

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#include<cctype>
#include<set>
#include<queue>
#include<vector>
#include<map>
#define pa pair<int,LL>
using namespace std;
typedef long long LL; inline LL read() {
LL x=,f=;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-;
for(;isdigit(ch);ch=getchar())x=x*+ch-'';return x*f;
} const int N = ;
pa A[N];
LL b[N]; bool Insert(LL x) {
for (int i = ; ~i; --i)
if ((x >> i) & ) {
if (b[i]) x ^= b[i];
else {
b[i] = x;
return ;
}
}
return ;
} int main() {
int n = read();
for (int i = ; i <= n; ++i)
A[i].second = read(), A[i].first = read();
sort(A + , A + n + );
LL Ans = ;
for (int i = n; i >= ; --i)
if (Insert(A[i].second)) Ans += A[i].first;
cout << Ans;
return ;
}

2460: [BeiJing2011]元素的更多相关文章

  1. BZOJ 2460: [BeiJing2011]元素

    2460: [BeiJing2011]元素 Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 878  Solved: 470[Submit][Statu ...

  2. BZOJ:2460[BeiJing2011]元素 (异或基+贪心)

    2460: [BeiJing2011]元素 Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 2910  Solved: 1535 题目链接:https: ...

  3. BZOJ 2460: [BeiJing2011]元素 线性基

    2460: [BeiJing2011]元素 Description 相传,在远古时期,位于西方大陆的 Magic Land 上,人们已经掌握了用魔法矿石炼制法杖的技术.那时人们就认识到,一个法杖的法力 ...

  4. bzoj 2460 [BeiJing2011]元素 (线性基)

    链接:https://www.lydsy.com/JudgeOnline/problem.php?id=2460 题意: 给你一堆矿石,矿石有a,b两种性质,取任意个矿石,满足取得的这些矿石a性质异或 ...

  5. BZOJ.2460.[BeiJing2011]元素(线性基 贪心)

    题目链接 线性基:https://blog.csdn.net/qq_36056315/article/details/79819714. \(Description\) 求一组矿石,满足其下标异或和不 ...

  6. BZOJ 2460 [BeiJing2011]元素(线性基模板题)

    Description 相传,在远古时期,位于西方大陆的 Magic Land 上,人们已经掌握了用魔法矿石炼制法杖的技术.那时人们就认识到,一个法杖的法力取决于使用的矿石.一般地,矿石越多则法力越强 ...

  7. BZOJ 2460: [BeiJing2011]元素 贪心,线性基

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2460 解法:从大到小排序,依次贪心的添加到当前集合就可以了,需要动态维护线性基.用拟阵证明 ...

  8. BZOJ 2460 [BeiJing2011]元素 ——线性基

    [题目分析] 线性基,由于最多有63个,只需要排序之后,动态的去维护线性基即可. [代码] #include <cstdio> #include <cstring> #incl ...

  9. bzoj 2460: [BeiJing2011]元素【线性基+贪心】

    先按魔力值从大到小排序,然后从大到小插入线性基中,如果插入成功就加上这个魔力值 因为线性基里是没有异或和为0的集合的,所以正确性显然,然后最优性,考虑放进去一个原来没选的,这样为了可行性就要删掉一个, ...

随机推荐

  1. redis集群热扩展(基于4.0.9)

    1:环境说明,首先说一下要做的事情,我们要迁移redis集群槽位,现有redis集群环境如下 我们看一下集群的基本信息: > cluster nodes 8ea64a0049e0b193296a ...

  2. 解决 There are no resources that can be added or removed from the server

    网上下载了一个项目,在eclipse中部署时,加载项目到tomcat中项目名称无法显示,报出There are no resources that can be added or removed fr ...

  3. MySQL学习分享--Thread pool实现

    基于<MySQL学习分享--Thread pool>对Thread pool架构设计的详细了解,本文主要对Thread pool的实现进行分析,并根据Mariadb和Percona提供的开 ...

  4. 多数据源报错 expected single matching bean but found 2: xxx,xxx

    问题: expected single matching bean but found 2: xxx,xxx 原因:在 Spring 容器中配置了两个类型Bean,Spring 容器将无法确定到底要用 ...

  5. AT89S52汇编实现l通过按键中断切换led灯的四种闪烁模式(单灯左移,单灯右移,双灯左移,双灯右移)

    ;通过P1口控制8路LED的四种闪烁模式,单独LED灯左移,单独LED灯右移,相邻两个灯左移,相邻两个灯右移;通过一个外部中断0来检测按键的跳变沿来切换闪烁模式,第一次按键按下弹起,灯的闪烁状态由单独 ...

  6. 多路I/O复用(select、poll、epoll)的比较学习:

    elect.poll.epoll之间的区别总结[整理]  转自:http://www.cnblogs.com/Anker/p/3265058.html   select,poll,epoll都是IO多 ...

  7. JavaScript基础之流程控制语句

    第三部分:流程控制语句 JavaScript代码是书写位置: JavaScript代码应该写在<script type=”text/javascript”></script>这 ...

  8. php实现动态随机验证码机制(CAPTCHA)

    php实现动态随机验证码机制 验证码(CAPTCHA)是“Completely Automated Public Turing test to tell Computers and Humans Ap ...

  9. 解决redis-cli command not found问题

    在使用其他服务器连接Redis服务器时,一般使用的语句是 [redis-cli -h IP -p port] 但是早上连接时报错:redis-cli command not found 在redis服 ...

  10. swift的enum基础

    其它语言的枚举: 符号化的整型常量的集合: swift的枚举: 可以是任何基础类型和无类型: If you are familiar with C, you will know that C enum ...