多校联合第二场 1005 卡片翻转
2014-07-28 21:40
295 查看
http://acm.hdu.edu.cn/showproblem.php?pid=4876
Problem Description
ZCC loves playing cards. He has n magical cards and each has a number on it. He wants to choose k cards and place them around in any order to form a circle. He can choose any several consecutive cards the number of which is m(1<=m<=k) to play
a magic. The magic is simple that ZCC can get a number x=a1⊕a2...⊕am, which ai means the number on the ith card he chooses. He can play the magic infinite times, but once he begin to play the magic, he can’t change anything in the card circle including
the order.
ZCC has a lucky number L. ZCC want to obtain the number L~R by using one card circle. And if he can get other numbers which aren’t in the range [L,R], it doesn’t matter. Help him to find the maximal R.
Input
The input contains several test cases.The first line in each case contains three integers n, k and L(k≤n≤20,1≤k≤6,1≤L≤100). The next line contains n numbers means the numbers on the n cards. The ith number a[i] satisfies 1≤a[i]≤100.
You can assume that all the test case generated randomly.
Output
For each test case, output the maximal number R. And if L can’t be obtained, output 0.
Sample Input
4 3 1
2 3 4 5
Sample Output
7
Hint ⊕ means xor
题意:选k个数,排成一个环,从这个环上取连续的几个数,得到他的异或值,求出最大的r,使l-r这些数都能异或出来,如果l<r输出0.
有个关键地方要剪枝,不然就TLE了,就是随机取了k个数之后,看能不能满足l-r,如果随机取的且没有按顺序都没满足,如果这个就不要排序再异或取值了。
Problem Description
ZCC loves playing cards. He has n magical cards and each has a number on it. He wants to choose k cards and place them around in any order to form a circle. He can choose any several consecutive cards the number of which is m(1<=m<=k) to play
a magic. The magic is simple that ZCC can get a number x=a1⊕a2...⊕am, which ai means the number on the ith card he chooses. He can play the magic infinite times, but once he begin to play the magic, he can’t change anything in the card circle including
the order.
ZCC has a lucky number L. ZCC want to obtain the number L~R by using one card circle. And if he can get other numbers which aren’t in the range [L,R], it doesn’t matter. Help him to find the maximal R.
Input
The input contains several test cases.The first line in each case contains three integers n, k and L(k≤n≤20,1≤k≤6,1≤L≤100). The next line contains n numbers means the numbers on the n cards. The ith number a[i] satisfies 1≤a[i]≤100.
You can assume that all the test case generated randomly.
Output
For each test case, output the maximal number R. And if L can’t be obtained, output 0.
Sample Input
4 3 1
2 3 4 5
Sample Output
7
Hint ⊕ means xor
题意:选k个数,排成一个环,从这个环上取连续的几个数,得到他的异或值,求出最大的r,使l-r这些数都能异或出来,如果l<r输出0.
有个关键地方要剪枝,不然就TLE了,就是随机取了k个数之后,看能不能满足l-r,如果随机取的且没有按顺序都没满足,如果这个就不要排序再异或取值了。
#include <stdio.h> #include <string.h> #include <iostream> using namespace std; int n,m,k; int s[100005],a[100005],b[100005]; int erfen(int x) { int l=0,r=n; int mid,ss=0;; while(l<=r) { mid=(l+r)/2; if(s[mid]<x) { ss=mid; l=mid+1; } else r=mid-1; } return ss; } int main() { while(~scanf("%d%d%d",&n,&m,&k)) { memset(a,0,sizeof(a)); memset(s,0,sizeof(s)); memset(b,0,sizeof(b)); for(int i=1;i<=n;i++) { scanf("%d",&a[i]); s[i]=s[i-1]+a[i]; } for(int i=1;i<=m;i++) scanf("%d",&b[i]); b[++m]=2e9; int sum=0,p=0,temp; for(int i=1;i<=m;i++) { if(n-p<b[i]-sum) { sum+=n-p; break; } else { temp=p+b[i]-sum-1; sum+=b[i]-sum; p=erfen(s[temp]-k); } } printf("%d\n",sum); } return 0; }
相关文章推荐
- HDU 4876 ZCC loves cards (2014多校联合训练第二场1005) 解题报告(暴力+剪枝)
- 多校联合 第二场 A
- 2015多校联合第二场 5305 friends 深搜
- 多校联合 第二场 E DP
- [DFS] 多校联合第二场 F题 Friends
- HDU 5305 Friends (搜索+剪枝) 2015多校联合第二场
- hdoj 4901 多校联合4 1005
- HDU 5303 Delicious Apples (DP) 2015多校联合第二场
- 2015多校联合第二场5308I Wanna Become A 24-Point Master
- hdoj 4939 2014多校联合7 1005
- poj 4604 Deque-----2013多校联合赛第一场--1005
- 2016多校联合第二场 HDU5741解题报告
- HDU 5305 Friends (搜索+剪枝) 2015多校联合第二场
- hdu 4617 2013多校联合训练第二场weapon简单的计算几何
- hdu 4619 warm up 2 并查集或搜索都可以做出来的题 2013多校联合训练第二场
- [找规律] 多校联合第二场 B题 Buildings
- 2017多校联合第二场 1001题 hdu 6045 Is Derek lying?
- 多校联合第二场(TJU)
- 2012 多校联合比赛第二场
- 2015多校联合第二场hdu5303Delicious Apples DP 类似最长山峰序列