CodeForces Round #173 (282E) - Sausage Maximization 字典树
来源:互联网 发布:网络炮王啥意思 编辑:程序博客网 时间:2024/06/05 11:44
练习赛的时候这道题死活超时....想到了高位确定后..低位不能对高位产生影响..并且高位要尽可能的为1..就是想不出比较好的方法了实现...
围观大神博客..http://www.cnblogs.com/zhj5chengfeng/archive/2013/05/14/3077621.html
思路很清晰了..没什么补充的..自己的思维还是不够啊...大神几句话点拨...豁然开朗...
Program:
#include<iostream>#include<string.h>#include<algorithm>#include<cmath>#include<queue>#include<stdio.h>#include<stack>#define oo 1000000007#define ll long long#define pi acos(-1.0)using namespace std;struct node{ int son[2]; ll w;}p[10000005];ll a[100005],totol,ans,_2jie[45];int num;void InsertToTrie(ll x){ int h=0,i,t; for (i=40;i>=0;i--) { if (x & _2jie[i]) t=1; else t=0; if (!p[h].son[t]) p[h].son[t]=++num; h=p[h].son[t]; } p[h].w=x; return;}ll SerchMax(ll x){ int h,i,t; h=0; for (i=40;i>=0;i--) { if (x & _2jie[i]) t=1; else t=0; if (p[h].son[1-t]) h=p[h].son[1-t]; else h=p[h].son[t]; } return p[h].w;} int main(){ int i,n; ll prefix,postfix; _2jie[0]=1; for (i=1;i<=40;i++) _2jie[i]=_2jie[i-1]*2; while (~scanf("%d",&n)) { postfix=0; for (i=1;i<=n;i++) scanf("%I64d",&a[i]),postfix^=a[i]; memset(p,0,sizeof(p)); ans=postfix; num=0; prefix=0; InsertToTrie(0); for (i=1;i<=n;i++) { prefix^=a[i]; InsertToTrie(prefix); postfix^=a[i]; ans=max(ans,SerchMax(postfix)^postfix); } printf("%I64d\n",ans); } return 0;}
- CodeForces Round #173 (282E) - Sausage Maximization 字典树
- Codeforces 282E Sausage Maximization(字典树)
- Codeforces 282E Sausage Maximization Trie字典树
- Codeforces 282E Sausage Maximization【字典树+贪心】
- Sausage Maximization - CodeForces 282 E Trie树
- Codeforces 282E(Sausage Maximization)
- CodeForces 282E Sausage Maximization
- Codeforces Round #173 (Div. 2) E. Sausage Maximization —— Trie树 + 前缀和
- Codeforces 282E Sausage Maximization (Trie)
- Codeforces 282E. Sausage Maximization【trie树(非指针版)】
- CF282 E Sausage Maximization[trie树]
- 【Codeforces 282E】Sausage Maximization 中文题意&题解&代码(C++)
- Educational Codeforces Round 12 E. Beautiful Subarrays【字典树】
- codeforces 665E (字典树)
- Codeforces Round #311 (Div. 2) E. Ann and Half-Palindrome (DP+字典树)
- Codeforces Round #311 (Div. 2) E - Ann and Half-Palindrome(字典树+dp)
- Codeforces Round #311 (Div. 2) E. Ann and Half-Palindrome 字典树
- Educational Codeforces Round 12 E. Beautiful Subarrays 预处理前缀+字典树优化★ ★
- tomcat端口被占用问题
- 回调函数有什么用,详细解释
- 自用。。从C#到java的程序移植经验
- java设计模式---桥接模式
- 未启用当前数据库的 SQL Server Service Broker
- CodeForces Round #173 (282E) - Sausage Maximization 字典树
- LNK1123: 转换到 COFF 期间失败: 文件无效或损坏
- Android编码规范
- PHP静态页面
- TCP协议
- hdu1334-Perfect Cubes
- build.porp解析 及如何使用属性值优化系统
- php apache mysql
- vim自动补全