Exam 2 Maximum Xor with Prefix and Suffix - Works Application 16
2016-06-06 20:57
399 查看
Maximum Xor with Prefix and Suffix
Description
We have N numbers as an array, you need to find a prefix array and a suffix arrar,which we can get the maximum xor value with all elements in them. Notice that for prefix[0,1] and suffix [r,n-1],do not intersect (l 小于 r), and they can be empty.Limits
-Memory limit per test : 256 megabytes-Time limit per test : The faster the better
Compile & Environment
C++
g++ Main.cc –o Main –fno-asm –Wall –lm –static –std=c++0x –DONLINE_JUDGEJava
J2SE8Maximum stack size is 50m
Input
The first line is one Number N( 1<=N<=100000)The second line contains N numbers ai (0 <= ai <=1e12) separated by space,
Which represents the array.
Output
Just output the maximum xor result.Sample Test
Input
31 2 3
Out
3Code
#include<iostream> #include <algorithm> long long pre[100005]; long long suf[100005]; long long arr[100005]; long long res[100005]; using namespace std; long long cal(long long zu[100005], int m, int n){ long long res = 0; for (int i = m; i <= n; i++){ res = max(res, zu[i]); } return res; } int main(){ int N; cin >> N; int i = 1; for (int i = 1; i <= N; i++){ cin >> arr[i]; } pre[0] = pre[N + 1] = suf[0] = suf[N + 1] = 0; for (int i = 1; i<N; i++){ pre[i] = pre[i - 1] ^ arr[i]; } for (int i = N; i >= 1; i--){ suf[i] = suf[i + 1] ^ arr[i]; } long long ans = 0; for (int i = 1; i <= N; i++){ ans = max(ans, max(cal(pre, 0, i), cal(suf, i + 1, N))); } cout << ans << endl; return 0; }
ca3d251f-0e7b-4258-8e68-8f7c9caa676+7
相关文章推荐
- Android每次运行项目时重新启动一个新的模拟器的解决办法
- iOS 如何创建一个线程,要求可以一直工作,不会执行一次就结束
- 《互动教程 for Xcode7 & Swift2》已成功发布在App Store
- 设置状态栏透明
- [Android] Fragment 中使用 getLayoutInflater() 的问题
- Android图片缓存之Glide进阶(四)
- 《互动教程 for Excel 2016》已成功发布在App Store
- 关于iosAPP跳转代理方法不调用问题
- AndroidStudio快捷键汇总
- 动态加载Dex的原理
- 网页微信配合谷歌浏览器实现自动发送信息
- 乐学成语
- Android 多线程间变量同步的问题
- [Android] 布局文件中控件属性值为 @null
- [Android] 去掉标题栏的方法
- Object Detection: To Be Higher Accuracy and Faster
- Object Detection: To Be Higher Accuracy and Faster
- LINE分享android利用系统自带分享实现LINE分享功能
- Debugging Memory Leaks on Android (for Beginners)
- Android打造万能适配器(一)再谈传统适配器