当前位置:网站首页>HDU4876ZCC loves cards(多校题)
HDU4876ZCC loves cards(多校题)
2022-07-07 18:44:00 【全栈程序员站长】
大家好,又见面了,我是全栈君。
ZCC loves cards
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 2362 Accepted Submission(s): 590
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
Author
镇海中学
Source
2014 Multi-University Training Contest 2
题意:给n个数。从中选出k个数,这k个数能够随意排列,一旦定了顺序就不能改变,在这个确定的顺序。选出m(m<=k)个数异或得到的值x,在这个顺序得到的全部x的值中找出一个最大值R,这些数中使得存在一个连续的范围L~R。
#include<stdio.h>
#include<string.h>
int n,k,L,ans[25];
int a[13],aa[13],R,flag[150];
int vist[10];
void find(int tk)
{
if(tk==k-1)
{
memset(flag,0,sizeof(flag));
for(int i=0;i<k-1;i++)
a[i+k]=a[i];
int maxa=0;
for(int i=0;i<k;i++)//枚举一个确定序列的连续片断的异或值
{
int x=a[i]; flag[x]=1; if(maxa<x)maxa=x;
for(int j=i+1;j-i+1<=k;j++)
{
x^=a[j]; flag[x]=1;if(maxa<x)maxa=x;
}
}
int r=0;
for(int i=L;i<=maxa;i++)//找出这个最大值R,使得这些数存在L~R范围的数都存在。
if(flag[i]==0)break;
else r=i;
if(r>R)R=r;
return ;
}
tk++;
for(int i=0;i<k;i++)
if(vist[i]==0)
{
a[tk]=aa[i]; vist[i]=1; find(tk); vist[i]=0;
}
}
bool panduan()//放宽条件(随意顺序)推断
{
memset(flag,0,sizeof(flag));
int maxa=0;
for(int i=1;i<(1<<k);i++)
{
int x=0;
for(int j=0;(1<<j)<=i;j++)
if((1<<j)&i)x^=aa[j];
flag[x]=1;
if(maxa<x)maxa=x;
}
int r=0;
for(int i=L;i<=maxa;i++)
if(flag[i]==0)break;
else r=i;
return r>R;
}
void CNM(int tk,int i)
{
if(tk==k-1)
{
if(panduan())
find(-1);
return ;
}
tk++;
for(int j=i+1;j<n;j++)
{
aa[tk]=ans[j]; CNM(tk,j);
}
}
int main()
{
while(scanf("%d%d%d",&n,&k,&L)>0)
{
R=0; memset(vist,0,sizeof(vist));
for(int i=0;i<n;i++)
scanf("%d",&ans[i]);
CNM(-1,-1);
printf("%d\n",R);
}
}
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/116456.html原文链接:https://javaforall.cn
边栏推荐
- Optimization cases of complex factor calculation: deep imbalance, buying and selling pressure index, volatility calculation
- 静态测试工具
- 使用高斯Redis实现二级索引
- [function recursion] do you know all five classic examples of simple recursion?
- CodeSonar通过创新型静态分析增强软件可靠性
- [award publicity] issue 22 publicity of the award list in June 2022: Community star selection | Newcomer Award | blog synchronization | recommendation Award
- Micro service remote debug, nocalhost + rainbow micro service development second bullet
- POJ 1742 Coins ( 单调队列解法 )「建议收藏」
- 使用高斯Redis实现二级索引
- Details of C language integer and floating-point data storage in memory (including details of original code, inverse code, complement, size end storage, etc.)
猜你喜欢
C语言 整型 和 浮点型 数据在内存中存储详解(内含原码反码补码,大小端存储等详解)
软件缺陷静态分析 CodeSonar 5.2 新版发布
Cantata9.0 | 全 新 功 能
OneSpin 360 DV新版发布,刷新FPGA形式化验证功能体验
解决使用uni-app MediaError MediaError ErrorCode -5
微服务远程Debug,Nocalhost + Rainbond微服务开发第二弹
95年专注安全这一件事 沃尔沃未来聚焦智能驾驶与电气化领域安全
Don't fall behind! Simple and easy-to-use low code development to quickly build an intelligent management information system
CodeSonar网络研讨会
H3C S7000/S7500E/10500系列堆叠后BFD检测配置方法
随机推荐
反诈困境,国有大行如何破局?
VMWare中虚拟机网络配置
4G设备接入EasyGBS平台出现流量消耗异常,是什么原因?
OneSpin | 解决IC设计中的硬件木马和安全信任问题
The latest version of codesonar has improved functional security and supports Misra, c++ parsing and visualization
Static analysis of software defects codesonar 5.2 release
Micro service remote debug, nocalhost + rainbow micro service development second bullet
微服务远程Debug,Nocalhost + Rainbond微服务开发第二弹
guava多线程,futurecallback线程调用不平均
Implement secondary index with Gaussian redis
嵌入式系统真正安全了吗?[ OneSpin如何为开发团队全面解决IC完整性问题 ]
How to meet the dual needs of security and confidentiality of medical devices?
【OpenCV 例程200篇】223. 特征提取之多边形拟合(cv.approxPolyDP)
目标:不排斥 yaml 语法。争取快速上手
Guava multithreading, futurecallback thread calls are uneven
【网络原理的概念】
Is embedded system really safe? [how does onespin comprehensively solve the IC integrity problem for the development team]
凌云出海记 | 易点天下&华为云:推动中国电商企业品牌全球化
使用camunda做工作流设计,驳回操作
awk处理JSON处理