[HDU5968]异或密码
[HDU5968]异或密码
题目大意:
数据共\(T(T\le100)\)组。每组给定一个长度为\(n(n\le100)\)的非负整数序列\(A(A_i\le1024)\),\(m(m\le100)\)个询问,每个询问包含一个整数\(x_i(|x_i|\le1024)\)。求该序列的子区间异或和与\(x_i\)接近程度值最小的区间长度;若有多个区间的异或和与\(x_i\)的接近程度值相同,则回答最长的区间长度。
思路:
求前缀异或和之后暴力枚举区间端点即可。
源代码:
#include<cstdio>
#include<cctype>
#include<climits>
#include<algorithm>
inline int getint() {
register char ch;
register bool neg=false;
while(!isdigit(ch=getchar())) neg|=ch=='-';
register int x=ch^'0';
while(isdigit(ch=getchar())) x=(((x<<2)+x)<<1)+(ch^'0');
return neg?-x:x;
}
const int N=101;
int a[N];
int main() {
for(register int T=getint();T;T--) {
const int n=getint();
for(register int i=1;i<=n;i++) {
a[i]=a[i-1]^getint();
}
const int m=getint();
for(register int i=0;i<m;i++) {
const int x=getint();
int min=INT_MAX,len;
for(register int i=1;i<=n;i++) {
for(register int j=0;j<i;j++) {
if(std::abs((a[i]^a[j])-x)<min) {
min=std::abs((a[i]^a[j])-x);
len=INT_MIN;
}
if(std::abs((a[i]^a[j])-x)==min) {
len=std::max(len,i-j);
}
}
}
printf("%d\n",len);
}
puts("");
}
return 0;
}
[HDU5968]异或密码的更多相关文章
- HDU5968 异或密码 —— 二分 + 边界的细节处理
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5968 异或密码 Time Limit: 2000/1000 MS (Java/Others) M ...
- HDU-5968异或密码
超级传送门 题目描述: 晨晨在纸上写了一个长度为N的非负整数序列{ai}.对于这个序列的一个连续子序列{al,al+1,…,ar}晨晨可以求出其中所有数异或的结果 alxoral+1xor...xor ...
- HDU 5968 异或密码
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- HDU 5968 异或密码 【模拟】 2016年中国大学生程序设计竞赛(合肥)
异或密码 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem Des ...
- hdu_5968_异或密码(预处理+二分)
题目链接:hdu_5968_异或密码 题意: 中午,不解释 题解: 前缀处理一下异或值,然后上个二分查找就行了,注意是unsigned long long #include<bits/stdc+ ...
- 异或密码---hdu5968(CCPC合肥,二分)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5968 思路:先把所有的连续异或值保存起来,排序,然后用二分找到距离x最近的那个点,判断即可: # ...
- HDU 5968:异或密码(暴力)
http://acm.hdu.edu.cn/showproblem.php?pid=5968 题意:中文题意. 思路:一开始不会做,后来发现数据范围很小,而且那个数要是连续的,所以可能把所有情况枚举出 ...
- 2016年中国大学生程序设计竞赛(合肥)-重现赛1008 HDU 5968
异或密码 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submis ...
- 《Xenogears》(异度装甲)隐含的原型与密码
<Xenogears>(异度装甲)隐含的原型与密码 X 彩虹按:一种高次元的“生命体”,因“事故”被抓来当成“超能源”,其实那不只是“无限的能源”而已,“它”是有意志的!在我们眼里看来,这 ...
随机推荐
- ARMV8 Procedure Call Standard
1.前言 2. 术语说明 Term Note ABI Application Binary Interface 应用程序二进制接口 EABI Embedded ABI 嵌入式ABI PCS Pro ...
- Linux电源管理【转】
转自:http://www.cnblogs.com/sky-zhang/archive/2012/06/05/2536807.html PM notifier机制: 应用场景: There are s ...
- 福利爬虫妹子图之获取种子url
import os import uuid from lxml import html import aiofiles import logging from ruia import Spider, ...
- activit流程引擎启动流程报错
代码如下: 目录结构 ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); @Test public void ...
- Go语言规格说明书 之 类型(Types)
go version go1.11 windows/amd64 本文为阅读Go语言中文官网的规则说明书(https://golang.google.cn/ref/spec)而做的笔记,完整的介绍Go语 ...
- STM32应用实例七:与宇电设备实现AI-BUS通讯
宇电的设备使用基于RS-485的自定义协议,协议本身比较简单,只有2条指令: 读:地址代号+52H(82) +要读的参数代号+0+0+校验码 写:地址代号+43H(67)+要写的参数代号+写入数低字节 ...
- MyEclipse2014安装插件的几种方式(适用于Eclipse或MyEclipse其他版本)
农历 乙未 羊年 十一月初九 周六 2015年12月19日 14:29 编辑者:刘军 标题: 服务器的搭建请参考该文:<Win7 x64 svn 服务器搭建> ============== ...
- WPS for Linux
https://www.cnblogs.com/gisalameda/p/6839482.html
- cf789d 图论计数,自环闭环
一开始没有思路,以为要判联通块. 其实不是判断联通块,而是判断边是否连在一起,没有连边的点可以忽略不计 /* 分情况讨论: 1.忽略自环,那么要取出两条相连的普通变作为只经过一次的边 2.一条自环,一 ...
- bzoj营业额统计
这个也是板子题吧,很水,求前驱后继即可 /* 插入,求前驱和后继 */ #include<iostream> #include<cstring> #include<cst ...