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 ...
随机推荐
- Javascript 跨域访问解决方案 总结
在客户端编程语言中,如javascript和ActionScript,同源策略是一个很重要的安全理念,它在保证数据的安全性方面有着重要的意义.同 源策略规定跨域之间的脚本是隔离的,一个域的脚本不能访问 ...
- HTML网页自动跳转
<meta http-equiv="refresh" content="3;URL=res.html">
- [android] The_connection_to_adb_is_down__and_a_severe_error_has_occured解决方案
初学安卓,这是我碰到的第一个问题,从网上找了些解决方法,同时也把问题解决了. 方案一 1.先把eclipse关闭. 2.在管理器转到你的android SDK 的platform-tools下, 如图 ...
- Laravel 程序架构设计思路:使用动作类
当我们谈论到应用程序的架构的时候,经常会问到一个经典的问题,那就是"这段代码应该放在哪里比较好". 因为 Laravel 是一个相当灵活的框架,所以要回答这个问题其实没那么容易.我 ...
- 【[国家集训队]小Z的袜子】
对于L,R的询问.设其中颜色为x,y,z的袜子的个数为a,b,c...那么答案即为(a*(a-1)/2+b*(b-1)/2+c*(c-1)/2....)/((R-L+1)*(R-L)/2)化简得:(a ...
- information_schema Introduction
information_schema介绍 information_schema数据库是MySQL自带的,里面的“表”保存着服务器当前的实时信息.它提供了访问数据库元数据的方式.元数据是关于数据的数据, ...
- Mongoose关于当天日期的查询
参考:https://blog.csdn.net/difffate/article/details/70312894 Ant Design Pro中,有关于日期的查询条件,但日期是以数字表示的 Req ...
- JAVAEE——宜立方商城04:图片服务器FastDFS、富文本编辑器KindEditor、商品添加功能完成
1. 学习计划 1.图片上传 a) 图片服务器FastDFS b) 图片上传功能实现 2.富文本编辑器的使用KindEditor 3.商品添加功能完成 2. 图片服务器的安装 1.存储空间可扩展. 2 ...
- Ninject
一.为什么要使用依赖注入框架 依赖注入框架也叫IoC容器.它的作用使类与类之间解耦 我们看看为什么要用依赖注入框架,举个几个梨子: 1,高度耦合的类 有一个Order类,Order类是用于订单操作的, ...
- Opencv学习笔记5:Opencv处理彩虹图、铜色图、灰度反转图
一.概述: 人类能够观察到的光的波长范围是有限的,并且人类视觉有一个特点,只能分辨出二十几种灰度,也就是说即使采集到的灰度图像分辨率超级高,有上百个灰度级,但是很遗憾,人们只能看出二十几个,也就是说信 ...