CodeForces Round #173 (282E) - Sausage Maximization 字典树
练习赛的时候这道题死活超时....想到了高位确定后..低位不能对高位产生影响..并且高位要尽可能的为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(字典树)
题目链接:282E Sausage Maximization 题目大意:给定一个序列A.要求从中选取一个前缀,一个后缀,能够为空,当时不能重叠.亦或和最大. 解题思路:预处理出前缀后缀亦或和,然后在字 ...
- Codeforces Round #173 (Div. 2) E. Sausage Maximization —— 字典树 + 前缀和
题目链接:http://codeforces.com/problemset/problem/282/E E. Sausage Maximization time limit per test 2 se ...
- Educational Codeforces Round 12 E. Beautiful Subarrays 字典树
E. Beautiful Subarrays 题目连接: http://www.codeforces.com/contest/665/problem/E Description One day, ZS ...
- 贪心 Codeforces Round #173 (Div. 2) B. Painting Eggs
题目传送门 /* 题意:给出一种方案使得abs (A - G) <= 500,否则输出-1 贪心:每次选取使他们相差最小的,然而并没有-1:) */ #include <cstdio> ...
- Codeforces Round #173 (Div. 2)
A. Bit++ 模拟. B. Painting Eggs 贪心,每个物品给使差值较小的那个人,根据题目的约数条件,可证明贪心的正确性. C. XOR and OR \(,,00 \to 00,01 ...
- Codeforces 455B A Lot of Games(字典树+博弈)
题目连接: Codeforces 455B A Lot of Games 题目大意:给定n.表示字符串集合. 给定k,表示进行了k次游戏,然后是n个字符串.每局開始.字符串为空串,然后两人轮流在末尾追 ...
- 【codeforces 514C】Watto and Mechanism(字典树做法)
[题目链接]:http://codeforces.com/contest/514/problem/C [题意] 给你n个字符串; 然后给你m个询问;->m个字符串 对于每一个询问字符串 你需要在 ...
- codeforces 1285D. Dr. Evil Underscores(字典树)
链接:https://codeforces.com/problemset/problem/1285/D 题意:给n个数a1,a2,a3.....an,找到一个数X,使得X 异或所有的ai ,得到的ma ...
- Codeforces 633 C Spy Syndrome 2 字典树
题意:还是比较好理解 分析:把每个单词反转,建字典树,然后暴力匹配加密串 注:然后我就是特别不理解,上面那种能过,而且时间很短,但是我想反之亦然啊 我一开始写的是,把加密串进行反转,然后单词正着建字典 ...
随机推荐
- Yii框架中的CURD操作
<?php $Admin = new Admin(); //查找多条记录,返回二维数组 $Admin->findAll(); $Admin->findAll("id = 2 ...
- dlib库学习之一
dlib库学习之一 1.介绍 跨平台 C++ 通用库 Dlib 发布 ,带来了一些新特性,包括概率 CKY 解析器,使用批量同步并行计算模型来创建应用的工具,新增两个聚合算法:中国低语 (Chines ...
- ipa制作
打包ipa步骤: 项目名称 -> edit scheme -> 如图选择release 点击close后,选择真机 然后command+b编译程序,右击app,show in Finder ...
- VS QT 配置OpenGL
在visual studio 下编译OpenGL代码出现以下错误,原因是vs没有自带opengl库,需要自己引入 无法解析的外部符号 __imp__glClear@4 无法解析的外部符号 __imp_ ...
- AnsiString 在 Delphi 中虽然不可用,但是,在 C++ 中可以用
[C++] C++ Builder 中 Ansi 编码的字符串在Android/iOS程序中显示的问题 呃,这个问题说起来,其实也不麻烦,C++ Builder 本身在 TEncoding 做了处理, ...
- elk 架构
- 基于visual Studio2013解决C语言竞赛题之0201温度转换
题目 解决代码及点评 #include <stdio.h> #include <stdlib.h> void main() { float f; float c; float ...
- HDU 4734 F(x) 2013 ACM/ICPC 成都网络赛
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4734 数位DP. 用dp[i][j][k] 表示第i位用j时f(x)=k的时候的个数,然后需要预处理下小 ...
- kinit manual
Name kinit - obtain and cache Kerberos ticket-granting ticket Synopsis kinit [-V] [-l lifetime] [-s ...
- PendingIntent.getBroadcast第四个参数flags
(1) android.app.PendingIntent.FLAG_UPDATE_CURRENT 如果PendingIntent已经存在,保留它并且只替换它的extra数据. (2) android ...