题意是在一个数列中找到一段连续的子串使其异或值与所给值最接近,求出子串长度,若有多组结果,输出最大长度。

做题之前一定多注意数据范围,这道题就可以直接暴力,用数组 p[ i ][ j ] 表示长度为 i 的数的第 j+1(从 0 开始)个异或值。

代码如下:

 #include <bits/stdc++.h>
using namespace std;
int a[];
int p[][];
int main()
{
int t,n,m,len,minl,r;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i = ; i < n; ++i)
scanf("%d",&a[i]);
memset(p,,sizeof(p));
for(int i = ; i < n; ++i)
for(int j = ; j < n-i; ++j)
for(int k = j; k <= j+i; ++k)
p[i][j]^=a[k];
scanf("%d",&m);
while(m--)
{
minl = 0xfffffff;
scanf("%d",&r);
for(int i = ; i < n; ++i)
for(int j = ; j < n-i; ++j)
{
if(abs(p[i][j]-r) < minl)
{
minl = abs(p[i][j]-r);
len = i+;
}
if(i+>len && abs(p[i][j]-r)==minl)
len = i+;
}
printf("%d\n",len);
}
printf("\n");
}
return ;
}

感谢这篇博客的作者:

https://blog.csdn.net/dt_zhangshuo/article/details/53056486

HDU 5968(异或计算 暴力)的更多相关文章

  1. HDU 5968 异或密码

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  2. HDU 5968 异或密码 【模拟】 2016年中国大学生程序设计竞赛(合肥)

    异或密码 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Des ...

  3. HDU 2920 分块底数优化 暴力

    其实和昨天写的那道水题是一样的,注意爆LL $1<=n,k<=1e9$,$\sum\limits_{i=1}^{n}(k \mod i) = nk - \sum\limits_{i=1}^ ...

  4. HDU 5968:异或密码(暴力)

    http://acm.hdu.edu.cn/showproblem.php?pid=5968 题意:中文题意. 思路:一开始不会做,后来发现数据范围很小,而且那个数要是连续的,所以可能把所有情况枚举出 ...

  5. hdu 4712 Hamming Distance(随机函数暴力)

    http://acm.hdu.edu.cn/showproblem.php?pid=4712 Hamming Distance Time Limit: 6000/3000 MS (Java/Other ...

  6. HDU 5442 Favorite Donut(暴力 or 后缀数组 or 最大表示法)

    http://acm.hdu.edu.cn/showproblem.php?pid=5442 题意:给出一串字符串,它是循环的,现在要选定一个起点,使得该字符串字典序最大(顺时针和逆时针均可),如果有 ...

  7. hdu 4768 异或运算

    http://acm.hdu.edu.cn/showproblem.php?pid=4768 貌似非常多人是用的二分 可是更好的做法貌似还是异或 对于第k个人.假设他接到偶数个传单.那么异或的结果还是 ...

  8. hdu 5277 YJC counts stars 暴力

    YJC counts stars Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...

  9. HDU 5762 Teacher Bo (暴力)

    Teacher Bo 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5762 Description Teacher BoBo is a geogra ...

随机推荐

  1. Task.Wait and “Inlining”

    “What does Task.Wait do?” Simple question, right? At a high-level, yes, the method achieves what its ...

  2. centos7防火墙导致不能访问的

    CentOS 7.0默认使用的是firewall作为防火墙,使用iptables必须重新设置一下 1.直接关闭防火墙 systemctl stop firewalld.service #停止firew ...

  3. 在Visual Studio 2017上配置Glut

    在Visual Studio 2017上配置Glut 作者:凯鲁嘎吉 - 博客园 http://www.cnblogs.com/kailugaji/ 在Visual Studio 2017上配置并使用 ...

  4. 我的第一个python web开发框架(25)——定制ORM(一)

    在开始编写ORM模块之前,我们需要先对db_helper进行重构,因为ORM最终生成的sql是需要转给db_helper来执行的,所以拥有一个功能完善.健壮的数据库操作类是非常必要的. 这是项目原db ...

  5. jvisualvm 连接 jstatd 远程监控 jvm 或 Visual GC提示"不受此JVM支持“

    Visual GC提示"不受此JVM支持",可以使用此方法解决. 一.添加配置文件 jstatd.all.policy [root@localhost /]# cd /usr/lo ...

  6. VMware14虚拟机下安装Centos6.5

    一.下载VMware14,CentOS6.5光盘映像文件. https://pan.baidu.com/s/1WaTBnYuNC5dLYM_Ra2bjBQ 二.安装过程 1.打开VMware虚拟机 — ...

  7. 【Python 03】程序设计与Python语言概述

    人生苦短,我用Python. Python在1990年诞生于荷兰,2010年Python2发布最后一版2.7,Python核心团队计划在2020年停止支持 Python2,目前Python3是未来. ...

  8. Redis学习笔记(2)——Redis的下载安装部署

    一.下载Redis Redis的官网下载页上有各种各样的版本,如图 但是官网下载的Redis项目不正式支持Windows.如果需要再windows系统上部署,要去GitHub上下载.我下载的是Redi ...

  9. java中 & ^ ~ 的运算

    java运算符 与(&).非(~).或(|).异或(^)   最近看HashMap源码,遇到了这样一段代码: 1 static final int hash(Object key) { 2 i ...

  10. Spring Security(三十六):12. Spring MVC Test Integration

    Spring Security provides comprehensive integration with Spring MVC Test Spring Security提供与Spring MVC ...