异或密码---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 题意:中文题意. 思路:一开始不会做,后来发现数据范围很小,而且那个数要是连续的,所以可能把所有情况枚举出 ...
随机推荐
- (2016弱校联盟十一专场10.3) A.Best Matched Pair
题目链接 #include<cstdio> #include<cstring> #include<algorithm> #include<stack> ...
- NavigationController
前面的一篇文章<iOS开发16:使用Navigation Controller切换视图>中的小例子在运行时,屏幕上方出现的工具栏就是Navigation Bar,而所谓UINavigati ...
- nginx 反向代理 配置 https 实现http https同时存在
server { listen ssl; #监听443端口 server_name www.app01.com; ssl on; #启用ssl加密 ssl_certificate /etc/cert/ ...
- 在Salesforce中创建Approval Process
在Salesforce中可以创建Approval Process来实现审批流程的功能,实际功能与我们常说的Workflow很相似,具体的设置步骤如下所示 1):选择对应的Object去创建对应的App ...
- LeetCode——Balanced Binary Tree(判断是否平衡二叉树)
问题: Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced bin ...
- HDU 4605 Magic Ball Game (dfs+离线树状数组)
题意:给你一颗有根树,它的孩子要么只有两个,要么没有,且每个点都有一个权值w. 接着给你一个权值为x的球,它从更节点开始向下掉,有三种情况 x=w[now]:停在此点 x<w[now]:当有孩子 ...
- Spring--通过注解来配置bean【转】
Spring通过注解配置bean 基于注解配置bean 基于注解来配置bean的属性在classpath中扫描组件 组件扫描(component scanning):Spring能够从classpat ...
- Hdu 3564 Another LIS 线段树+LIS
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...
- keyCode,charCode,which
1.触发顺序keydown keypress keyup,但keypress事件只有输入相关按键才会触发,功能按键不会触发keypress事件(keypress事件有个额外的charCode属性) 2 ...
- 洛谷 P2725 邮票 Stamps Label:DP
题目背景 给一组 N 枚邮票的面值集合(如,{1 分,3 分})和一个上限 K —— 表示信封上能够贴 K 张邮票.计算从 1 到 M 的最大连续可贴出的邮资. 题目描述 例如,假设有 1 分和 3 ...