http://acm.hdu.edu.cn/showproblem.php?pid=5968

题意:中文题意。

思路:一开始不会做,后来发现数据范围很小,而且那个数要是连续的,所以可能把所有情况枚举出来很小吧。打了个表发现 100 只有 4950 个,然后直接暴力枚举每一种情况,放在Hash里面标记是否出现过这个数,再弄一个len数组放置每一种情况长度,然后对答案分别向左和向右找最长的长度就好了。

 #include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <iostream>
#include <stack>
#include <map>
#include <queue>
using namespace std;
#define N 100010
#define INF 0x3f3f3f3f
bool Hash[N];
int len[N];
//vector<int> v;
int num[];
int main()
{
int t;
scanf("%d", &t);
while(t--) {
int n;
scanf("%d", &n);
for(int i = ; i <= n; i++) scanf("%d", &num[i]);
memset(Hash, , sizeof(Hash));
memset(len, , sizeof(len));
for(int i = ; i <= n; i++) {
for(int j = ; j + i - <= n; j++) {
int tmp = ;
for(int k = ; k < i; k++) {
tmp ^= num[k + j];
}
Hash[tmp] = ;
len[tmp] = max(len[tmp], i);
// v.push_back(tmp);
}
}
// puts("----------------");
// for(int i = 0; i < v.size(); i++) printf("%d ", v[i]);
// puts("");
// puts("----------------");
int q;
scanf("%d", &q);
while(q--) {
int ask;
scanf("%d", &ask);
int l = , ans = -;
bool f = ;
while(!f) {
if(ask - l >= && Hash[ask-l]) {
ans = len[ask-l];
f = ;
// printf("1 : %d, %d\n", ask - l, ans);
}
if(Hash[ask+l]) {
ans = max(len[ask+l], ans);
// printf("2 : %d, %d\n", ask + l, ans);
f = ;
} l++;
}
printf("%d\n", ans);
}
puts("");
}
return ;
}

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 5968(异或计算 暴力)

    题意是在一个数列中找到一段连续的子串使其异或值与所给值最接近,求出子串长度,若有多组结果,输出最大长度. 做题之前一定多注意数据范围,这道题就可以直接暴力,用数组 p[ i ][ j ] 表示长度为 ...

  4. HDU5968 异或密码 —— 二分 + 边界的细节处理

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5968 异或密码 Time Limit: 2000/1000 MS (Java/Others)    M ...

  5. [HDU5968]异或密码

    [HDU5968]异或密码 题目大意: 数据共\(T(T\le100)\)组.每组给定一个长度为\(n(n\le100)\)的非负整数序列\(A(A_i\le1024)\),\(m(m\le100)\ ...

  6. 2016年中国大学生程序设计竞赛(合肥)-重现赛1008 HDU 5968

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

  7. hdu_5968_异或密码(预处理+二分)

    题目链接:hdu_5968_异或密码 题意: 中午,不解释 题解: 前缀处理一下异或值,然后上个二分查找就行了,注意是unsigned long long #include<bits/stdc+ ...

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

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

  9. SSH密码暴力破解及防御实战

    SSH密码暴力破解及防御实战 一.Hydra(海德拉) 1.1 指定用户破解 二.Medusa(美杜莎) 2.1 语法参数 2.2 破解SSH密码 三.Patator 3.1 破解SSH密码 四.Br ...

随机推荐

  1. iOS 重写UITableViewCell之动态获取label文字的宽度进行布局

    #import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicationDelegate> @pr ...

  2. [gerrit] Auto Add Reviewer When Push Code

    1. ${PROJECT_ROOT}/.git/config 加入如下代码 [remote "review"] url = ssh://${username}@codeserver ...

  3. SQL Server Index详解

    最近在进行数据库调优,对索引的使用和其内部的运转一知半解.在园子里看到一篇相关文章非常好.留下印记以便日常查找. http://www.cnblogs.com/xwdreamer/archive/20 ...

  4. Dive into python 实例学python (1) —— 函数和测试

    odbchelper.py def buildConnectionString(params): """Build a connection string from a ...

  5. bnuoj 44359 快来买肉松饼

    http://www.bnuoj.com/contest/problem_show.php?pid=44359 快来买肉松饼 Time Limit: 5000 ms     Case Time Lim ...

  6. SQL 面向对象

    1.面向过程 int a = 10;int b =5;int c = a+b; int r1 = 10;int r2 = 5;double c = r1*r1*3.14 - r2*r2*3.14 缺点 ...

  7. Java基础(44):ArrayList使用详解

    1.什么是ArrayList ArrayList就是传说中的动态数组,用MSDN中的说法,就是Array的复杂版本,它提供了如下一些好处:    a.动态的增加和减少元素    b.实现了IColle ...

  8. HDU 4833 Best Financing(DP)(2014年百度之星程序设计大赛 - 初赛(第二轮))

    Problem Description 小A想通过合理投资银行理财产品达到收益最大化.已知小A在未来一段时间中的收入情况,描述为两个长度为n的整数数组dates和earnings,表示在第dates[ ...

  9. Cocos2d-x游戏开发之计时器

    首先写一个计时器的头文件GameTimer.h: #ifndef _GAME_TIMER_H_ #define _GAME_TIMER_H_ #include "cocos2d.h" ...

  10. C#写好的类库dll怎么在别人调用的时候也能看到注释?

    菜单 Project -> 'xxxx' Properties -> Build -> Output -> 勾上 XML Documentation file