异或密码---hdu5968(CCPC合肥,二分)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5968
思路:先把所有的连续异或值保存起来,排序,然后用二分找到距离x最近的那个点,判断即可;
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <bitset>
#include <iostream>
#include <time.h> typedef long long LL; using namespace std; const int N = ;
const double eps = 1e-;
const int INF = 0x3f3f3f3f;
const int mod = ; struct node
{
int len, num;
}c[N*N]; int a[N], b[N], k, c1[N*N], c2[N*N]; bool cmp(node p, node q)
{
if(p.num!=q.num)
return p.num<q.num;
return p.len < q.len;
} int Find(int num)
{
int pos = upper_bound(c1, c1+k, num)-c1;
return c2[pos-];
} int solve(int x)///Find x in the c[];
{
int pos = lower_bound(c1, c1+k, x)-c1; if(pos == || c1[pos] == x)///如果数组中含有x,那就找到异或值为x的最大长度;
return Find(c1[pos]); int p = abs(c1[pos]-x);
int q = abs(c1[pos-]-x);
int ans1 = Find(c1[pos]);
int ans2 = Find(c1[pos-]); if(p < q || (p == q && ans1>ans2))
return ans1;
return ans2;
} int main()
{
int T, n, m; scanf("%d", &T); while(T --)
{
scanf("%d", &n); memset(a, , sizeof(a));
memset(b, , sizeof(b));
memset(c, , sizeof(c)); for(int i=; i<=n; i++)
{
scanf("%d", &a[i]);
b[i] = b[i-]^a[i];
} k = ; for(int i=; i<=n; i++)/// the length is i;
{
for(int j=; i+j-<=n; j++)/// from j to j+i;
{
int num = b[j+i-]^b[j-];
c[k].len = i;
c[k++].num = num;
}
} sort(c, c+k, cmp); for(int i=; i<k; i++)
{
c1[i] = c[i].num;
c2[i] = c[i].len;
} scanf("%d", &m); for(int i=; i<=m; i++)
{
int x; scanf("%d", &x); int ans = solve(x); printf("%d\n", ans);
}
printf("\n");
}
return ;
}
异或密码---hdu5968(CCPC合肥,二分)的更多相关文章
- HDU5968 异或密码 —— 二分 + 边界的细节处理
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5968 异或密码 Time Limit: 2000/1000 MS (Java/Others) M ...
- 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]异或密码
[HDU5968]异或密码 题目大意: 数据共\(T(T\le100)\)组.每组给定一个长度为\(n(n\le100)\)的非负整数序列\(A(A_i\le1024)\),\(m(m\le100)\ ...
- HDU 5968 异或密码
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- HDU-5968异或密码
超级传送门 题目描述: 晨晨在纸上写了一个长度为N的非负整数序列{ai}.对于这个序列的一个连续子序列{al,al+1,…,ar}晨晨可以求出其中所有数异或的结果 alxoral+1xor...xor ...
- BZOJ 4103 [Thusc 2015]异或运算 (可持久化01Trie+二分)
题目大意:给你一个长方形矩阵,位置$i,j$上的数是$a_{i}\;xor\;b_{j}$,求某个子矩阵内第$K$大的值 最先想的是二分答案然后验证,然而是$O(qnlogmloga_{i})$,不出 ...
- 2016 CCPC 合肥赛区 平行四边形//打铁记录..... 背锅还是我在行 此处@ctr 233
也希望自己记住这些题并不是真的很难很难... 平行四边形... 这个题要两个直线上的两个点和给出点中的两个点组成的平行四边形面积最大. 确定两个点后,发现线上的点随之确定.那么我们解出线上的点 然后求 ...
- HDU 5968:异或密码(暴力)
http://acm.hdu.edu.cn/showproblem.php?pid=5968 题意:中文题意. 思路:一开始不会做,后来发现数据范围很小,而且那个数要是连续的,所以可能把所有情况枚举出 ...
随机推荐
- jQuery 名称冲突
jQuery 名称冲突 jQuery 使用 $ 符号作为 jQuery 的简介方式. 某些其他 JavaScript 库中的函数(比如 Prototype)同样使用 $ 符号. jQuery 使用名为 ...
- code first 创建和初始化数据库
1.前言 Code First是Entity Framework提供的一种新的编程模型.通过Code First我们可以在还没有建立数据库的情况下就开始编码,然后通过代码对象来生成数据库.当然我们在实 ...
- C语言字符串操作总结大全
1)字符串操作 strcpy(p, p1) 复制字符串 函数原型strncpy(p, p1, n) 复制指定长度字符串 函数原型strcat(p, p1) 附加字符串 函数原型strn ...
- 【leetcode】Unique Binary Search Trees (#96)
Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For examp ...
- 2.oracle 12c 创建-访问-关闭-删除PDB
1.创建PDB SQL> select name from v$datafile; NAME ------------------------------------------------ ...
- MVC 好记星不如烂笔头之 ---> 页面压缩GIP
public class BaseController : Controller { /// <summary> /// Called before the action method i ...
- UWP 下拉刷新控件(PullToRefreshControl)
最近项目里面有下拉刷新的需求,自己做了一个,效果还不错. <Style TargetType="local:PullToRefreshControl"> <Set ...
- UWP x:bind
x:bind 作为win10 新特性,它好在哪?为什么要用它. 最近做UWP,对代码进行重构,对它有了一些了解. 先说优点: 1.性能高,内存小(相比传统的binding) 没图没真相,我先上2张图. ...
- node 关键点总结
1.I/O密集的地方尽量不要用require.(require是同步I/O操作) eg:正在运行一个HTTP服务器,如果在每个进入的请求上都用了require,就会遇到性能问题.所以通常在程序最初加载 ...
- 基于socket的客户端和服务端聊天简单使用 附Demo
功能使用 服务端 分离一个不停接受客户端请求的线程 接受不客户端请求的线程中,再分离就收消息的线程 几大对象分别是 IPEndPoint IP终结点 服务端Socket,绑定终结点Bind,启动监听L ...