ZCC loves cards

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 260    Accepted Submission(s): 7

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
 

题意:有N张牌。每张牌都有其权值ai。然后有一个幸运数L。从N个数取K个数围城一个圈,顺序随意。然后能够这个魔术师能够从这k张牌中取连续的随意张牌得到一个数值h=a1^a2^a3...假设他想要[L,R]这个范围的值都能取到,问R最大是多少。

题解:用二进制状态把取出k的多种情况存入sta数组中。然后去模拟找出最大的R。TLE.

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <list>
#include <vector>
using namespace std;
#define LL __int64
LL sta[100010];
int a[50];
int main()
{
int n,m,i,j,k,i1,i2,i3,i4,i5,i6,L;
while (3==scanf("%d%d%d",&n,&m,&L))
{
memset(sta,0,sizeof(sta));
memset(a,0,sizeof(a));
LL t=0,s;
for (i=0;i<n;i++)
scanf("%d",&a[i]);
if (m==1)
{
for (i=0;i<n;i++)
sta[++t]=1<<i;
}
else if (m==2)
{
for (i=0;i<n-1;i++)
for (i1=0;i1<n-(i+1);i1++)
{
s=(1<<(i+i1+1))+(1<<i1);
sta[++t]=s;
}
}
else if (m==3)
{
for (i=0;i<n-2;i++)
for (j=0;j<n-(i+1)-1;j++)
for (k=0;k<n-2-i-j;k++)
{
s=(1<<(i+k+j+2))+(1<<(j+k+1))+(1<<k);
sta[++t]=s;
}
}
else if (m==4)
{
for (i=0;i<n-3;i++)
for (i1=0;i1<n-(i+1)-2;i1++)
for (i2=0;i2<n-i-i1-3;i2++)
for (i3=0;i3<n-i1-i2-i-3;i3++)
{
s=(1<<(i+i1+i2+i3+3))+(1<<(i1+i2+i3+2))+(1<<(i2+i3+1))+(1<<i3);
sta[++t]=s;
}
}
else if (m==5)
{
for (i=0;i<n-3;i++)
for (i1=0;i1<n-(i+1)-2;i1++)
for (i2=0;i2<n-i-i1-3;i2++)
for (i3=0;i3<n-i1-i2-i-4;i3++)
for (i4=0;i4<n-i1-i2-i3-i-4;i4++)
{
s=(1<<(i+i1+i2+i3+i4+4))+(1<<(i1+i2+i3+i4+3))+(1<<(i2+i3+i4+2))+(1<<(i3+i4+1))+(1<<(i4));
sta[++t]=s;
}
}
else
{
for (i=0;i<n-3;i++)
for (i1=0;i1<n-(i+1)-2;i1++)
for (i2=0;i2<n-i-i1-3;i2++)
for (i3=0;i3<n-i1-i2-i-4;i3++)
for (i4=0;i4<n-i1-i2-i3-i-5;i4++)
for (i5=0;i5<n-i-i1-i2-i3-i4-5;i5++)
{
s=(1<<(i+i1+i2+i3+i4+i5+5))+(1<<(i1+i2+i3+i4+i5+4))+(1<<(i2+i3+i4+i5+3))+(1<<(i3+i4+i5+2))+(1<<(i4+i5+1))+(1<<i5);
sta[++t]=s;
}
}
/*cout<<t<<endl;
for (i=1;i<=t;i++)
cout<<sta[i]<<endl;*/
int ss[50],ans=0;
memset(ss,0,sizeof(ss));
for (i=1;i<=t;i++)
{
map<int,int>mp;
int l=0;
for (j=0;j<n;j++)
if ((1<<j) & sta[i])
ss[l++]=j; //序列出来了 cout<<ss<<endl;
sort(ss,ss+l);
do
{
/*for (i=0;i<m;i++)
printf("%d ",a[ss[i]]);
cout<<endl;*/
mp.clear();
int s1[50];
memset(s1,0,sizeof(s1));
for (i1=0;i1<m;i1++)
{
s1[i1]=s1[i1+m]=a[ss[i1]];
mp[s1[i1]]=1;
}
for (i1=0;i1<m;i1++)
{
int h=s1[i1];
for (j=i1+1;j<i1+m;j++)
{
h=h^s1[j];
mp[h]=1;
}
}
int h=L;
while (mp[h]) h++;
if (h!=L && h-1>ans) ans=h-1;
}while (next_permutation(ss, ss+l));
}
cout<<ans<<endl;
}
return 0;
}

多校训练赛2 ZCC loves cards的更多相关文章

  1. 2014---多校训练2(ZCC Loves Codefires)

    ZCC Loves Codefires Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  2. HDU 4876 ZCC loves cards(暴力剪枝)

    HDU 4876 ZCC loves cards 题目链接 题意:给定一些卡片,每一个卡片上有数字,如今选k个卡片,绕成一个环,每次能够再这个环上连续选1 - k张卡片,得到他们的异或和的数,给定一个 ...

  3. hdu 4876 ZCC loves cards(暴力)

    题目链接:hdu 4876 ZCC loves cards 题目大意:给出n,k,l,表示有n张牌,每张牌有值.选取当中k张排列成圈,然后在该圈上进行游戏,每次选取m(1≤m≤k)张连续的牌,取牌上值 ...

  4. HDOJ 4876 ZCC loves cards

    枚举组合,在不考虑连续的情况下推断能否够覆盖L...R,对随机数据是一个非常大的减枝. 通过检測的暴力计算一遍 ZCC loves cards Time Limit: 4000/2000 MS (Ja ...

  5. HDU6578 2019HDU多校训练赛第一场 1001 (dp)

    HDU6578 2019HDU多校训练赛第一场 1001 (dp) 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6578 题意: 你有n个空需要去填,有 ...

  6. HDU6579 2019HDU多校训练赛第一场1002 (线性基)

    HDU6579 2019HDU多校训练赛第一场1002 (线性基) 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6579 题意: 两种操作 1.在序列末 ...

  7. HDU4876:ZCC loves cards

    Problem Description ZCC loves playing cards. He has n magical cards and each has a number on it. He ...

  8. 2018牛客网暑假ACM多校训练赛(第三场)I Expected Size of Random Convex Hull 计算几何,凸包,其他

    原文链接https://www.cnblogs.com/zhouzhendong/p/NowCoder-2018-Summer-Round3-I.html 题目传送门 - 2018牛客多校赛第三场 I ...

  9. 2018牛客网暑假ACM多校训练赛(第三场)G Coloring Tree 计数,bfs

    原文链接https://www.cnblogs.com/zhouzhendong/p/NowCoder-2018-Summer-Round3-G.html 题目传送门 - 2018牛客多校赛第三场 G ...

随机推荐

  1. WEB 3D SVG CAD 向量 几个实施

    一.他们所有的发展.从地上爬起来 VML+SVG发展矢量地图.你并不需要导入第三方的图片作为背景,直接在地图编辑器可以在底图内容编辑,由于岩石.巷道.煤层.画水.础地图样子再在其上面画出智慧线等设备, ...

  2. 网络基础知识系列:阐述VLAN和Trunk

    网络性能是影响的效率的重要因素. 大的广播域分割方法,旨在提高网络性能.一个接口上,可是,路由器的LAN接口数量有限,它的主要功能是在网络间数据传输,而不是对终端设备提供网络接入. 訪问LAN的功能还 ...

  3. Eclipse建筑物SSH(struts-2.2.3 + spring-2.5.6 + hibernate-3.6.8)相框-随着源代码

    一直想自己搭建一个ssh框架,这次因为编写demo的须要,就亲手搭建了一下,并逐步測试!以下进入正题: 创建Struts项目 整合步骤: 1,在Eclipse中创建一个DynamicWeb Proje ...

  4. SqlServer中存储过程中将Exec的执行结果赋值给变量输出

    原文 SqlServer中存储过程中将Exec的执行结果赋值给变量输出 背景: 遇到这样一种情况:动态向存储过程中传入表名和表的某些属性(这里用到的是主键ID),然后利用这两个变量查出一条数据的某些字 ...

  5. linux权限和ntfs知识文件系统权限

    左右ntfs权限的问题 文件权限: [-dcbps][u:rwx][g:rwx][a:rwx] 当中: r=4, w=2, x=1,  u=owner, g=group, a=all user     ...

  6. Sass 基础和入门

    css本身很有趣,但是随着样式表变大,会越来越复杂,更加难以管理.css预处理器在这里就能帮上忙了.SASS 让你使用在css中不存在的特性,譬如变量.嵌套.mixins(混入),继承和一些其他好的特 ...

  7. zepto.js 源码注释备份

    /* Zepto v1.0-1-ga3cab6c - polyfill zepto detect event ajax form fx - zeptojs.com/license */ ;(funct ...

  8. Cordova WP8 平台安装部署

    原文:Cordova WP8 平台安装部署 Cordova是一个开放源码移动开发框架. 它允许您使用标准的 web 技术如 HTML5. CSS3 和 JavaScript 进行跨平台开发,避免每个移 ...

  9. HDU 2203 亲串(kmp)

    Problem Description 随着人们年龄的增长更大,更聪明还是越大越愚蠢,这是一个值,相同的问题Eddy也一直在思考,由于他在非常小的时候就知道亲和串怎样推断了,可是发现,如今长大了却不知 ...

  10. 【MySQL案件】ERROR 1665 (HY000)

    转载请注明: http://blog.csdn.net/jason_asia/article/details/36240815 1.1.1. ERROR 1665 (HY000) [环境的叙述性说明] ...