HDOJ 4876 ZCC loves cards
枚举组合,在不考虑连续的情况下推断能否够覆盖L...R,对随机数据是一个非常大的减枝.
通过检測的暴力计算一遍
ZCC loves cards
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1346 Accepted Submission(s): 335
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.
You can assume that all the test case generated randomly.
4 3 1
2 3 4 5
7Hint⊕ means xor
pid=4881" target="_blank" style="color:rgb(26,92,200); text-decoration:none">4881
pid=4880" target="_blank" style="color:rgb(26,92,200); text-decoration:none">4880
pid=4879" target="_blank" style="color:rgb(26,92,200); text-decoration:none">4879
pid=4878" target="_blank" style="color:rgb(26,92,200); text-decoration:none">4878
4877Statistic | pid=4876" style="color:rgb(26,92,200); text-decoration:none">Submit
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm> using namespace std; int n,k,m,a[30],save[30],have[30],R,L;
bool vis[3000],cx[200]; void ckMax(int num,int sum)
{
vis[sum]=true;
if(num==k) return ;
ckMax(num+1,sum^save[num]);
ckMax(num+1,sum);
} bool ck()
{
memset(vis,0,sizeof(vis));
ckMax(0,0);
for(int i=L;i<=R;i++)
{
if(vis[i]==false) return false;
}
return true;
} void CALU()
{
if (!ck()) return;
for(int i=0;i<k;i++)
have[i]=save[i];
do
{
memset(vis,0,sizeof(vis));
for(int i=0;i<k;i++)
{
int x=0;
for(int j=0;j<k;j++)
{
x^=have[(i+j)%k];
vis[x]=true;
}
}
for(int i=L;i<=L+k*k;i++)
{
if(vis[i]==false) break;
R=max(R,i);
}
}while(next_permutation(have,have+k-1));
} void dfs(int num,int id)
{
if(num==k)
{
CALU();
return ;
}
for(int i=id;i<n;i++)
{
save[num]=a[i];
dfs(num+1,i+1);
}
} int main()
{
while(scanf("%d%d%d",&n,&k,&L)!=EOF)
{
R=L-1;
for(int i=0;i<n;i++)
scanf("%d",a+i);
sort(a,a+n);
dfs(0,0);
if(R<L) printf("0\n");
else printf("%d\n",R);
}
return 0;
}
HDOJ 4876 ZCC loves cards的更多相关文章
- HDU 4876 ZCC loves cards(暴力剪枝)
HDU 4876 ZCC loves cards 题目链接 题意:给定一些卡片,每一个卡片上有数字,如今选k个卡片,绕成一个环,每次能够再这个环上连续选1 - k张卡片,得到他们的异或和的数,给定一个 ...
- hdu 4876 ZCC loves cards(暴力)
题目链接:hdu 4876 ZCC loves cards 题目大意:给出n,k,l,表示有n张牌,每张牌有值.选取当中k张排列成圈,然后在该圈上进行游戏,每次选取m(1≤m≤k)张连续的牌,取牌上值 ...
- HDU 4876 ZCC loves cards _(:зゝ∠)_ 随机输出保平安
GG,,,g艹 #include <cstdio> #include <iostream> #include <algorithm> #include <st ...
- 多校训练赛2 ZCC loves cards
ZCC loves cards Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- HDU4876:ZCC loves cards
Problem Description ZCC loves playing cards. He has n magical cards and each has a number on it. He ...
- HDU4876ZCC loves cards(多校题)
ZCC loves cards Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Tot ...
- hdu 5288 ZCC loves straight flush
传送门 ZCC loves straight flush Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K ...
- HDU 5228 ZCC loves straight flush( BestCoder Round #41)
题目链接:pid=5228">ZCC loves straight flush pid=5228">题面: pid=5228"> ZCC loves s ...
- 2014---多校训练2(ZCC Loves Codefires)
ZCC Loves Codefires Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
随机推荐
- sass问题
用sass的minix定义一些代码片段,且可传参数 /** * @module 功能 * @description 生成全屏方法 * @method fullscreen * @version 1. ...
- 《精通Python设计模式》学习结构型之外观模式
这个我在工作中也有所应用的. 就是在真正的实现层上面,再封装一个函数的调用的. 这样就可以在内层函数作真正实现, 而外层调用函数对外开放, 隔离内外的变化性. from enum import Enu ...
- day5作业购物商城+ATM
模拟实现一个ATM + 购物商城程序 1.额度 15000或自定义 2.实现购物商城,买东西加入购物车,调用信用卡接口结账 3.可以提现,手续费5% 4.每月22号出账单,每月10号为还款日,过期未还 ...
- MFC+WinPcap编写一个嗅探器之六(分析模块)
这一节是程序的核心,也是最复杂的地方 首先需要明白的一点是,一般对于一个有界面的程序来说,往往需要多线程.本程序中除了界面线程外,抓包需要另外创建一个新的线程.在写抓包函数之前,首先要将前面两个模块的 ...
- python的简介(一)
1. Python的种类 Cpython Python的官方版本,使用C语言实现,使用最为广泛,CPython实现会将源文件(py文件)转换成字节码文件(pyc文件),然后运行在Python虚 ...
- python和mongodb简单交互
python和mongodb简单交互 1.安装pymongo: pip3 install pymongo 2.pymongo的简单用法: # /usr/bin/env python3 import p ...
- Linux下 rz 和 sz 命令的安装与使用
目录 Linux下 rz 和 sz 命令的安装与使用 rz/sz命令的安装 sz命令-发送文件到本地(下载): rz命令-本地上传文件到服务器(上传): 声明 Linux下 rz 和 sz 命令的安装 ...
- Ionic入门十:icon(图标)
ionic 也默认提供了许多的图标,大概有500多个.用法也非常的简单: <i class="icon ion-star"></i> 图标列表如下:   ...
- 微信JS-SDK之图像接口开发详解
由于现在手头的项目中有一个上传证件照认证的功能(手机端),之前的思路是直接点击上传,然后直接将图片上传到服务器去,这篇文章有讲到(http://www.cnblogs.com/it-cen/p/453 ...
- Spring Boot使用Log4j Implemented Over SLF4J生成日志并在控制台打印
Spring Boot设置切面,执行方法的时候在控制台打印出来,并生成日志文件 引入依赖: <!--日志--> <dependency> <groupId>org. ...