Codeforces 460 D. Little Victor and Set
暴力+构造
If r - l ≤ 4 we can all subsets of size not greater than k.
Else, if k = 1, obviously that answer is l. If k = 2,
answer is 1, because xor of numbers 2x and 2x + 1 equls 1.
If k ≥ 4 answer is 0 because xor of
to pairs with xor 1 is 0.
If k = 3, we can choose numbers 2x and 2x + 1 with xor 1.
So we need to know, if we can get xor equals 0. Suppose that
there are 3 such numbers x, y and z (r ≥ x > y > z ≥ l)
with xor equals 0. Consider the most non-zero bit of numberx.
At the same bit of y it's also 1, because xor equls
0, and y > z. Consider the next bit of numbers. If z have 0 there,
we have to do next: set the previous bit of numbers x and y equals 0,
and set current bit equals 1. Obviously xor still equals
0, z hadn't changed and numbers x and y stood
closer to z, so they are still at [l, r].And x > y.Consider
the next bit of numbers. If z has zero here than we will change most bits of x и y at
the same way and so on. z > 0, so somewhen we will get to bit in which z has 1.
Since xorequals 0, the same bit of x would
be 1 because x > y, and y would
have 0 there. At the next bits we will change bit in x to 0,
and in numbers y and z to 1.Finally z would
be greater or equal than before, and x would be less or greater than before, and x > y > z would
be correct. So, we have the next: if such numbers x, y and z exist
than also exist numbers:
1100…000
1011…111
0111…111
with xor equals 0. There are not much such triples, so we
can check them.
1 second
256 megabytes
standard input
standard output
Little Victor adores the sets theory. Let us remind you that a set is a group of numbers where all numbers are pairwise distinct. Today Victor wants to find a set of integers S that
has the following properties:
- for all x
the
following inequality holds l ≤ x ≤ r; - 1 ≤ |S| ≤ k;
- lets denote the i-th element of the set S as si;
valuemust
be as small as possible.
Help Victor find the described set.
The first line contains three space-separated integers l, r, k (1 ≤ l ≤ r ≤ 1012; 1 ≤ k ≤ min(106, r - l + 1)).
Print the minimum possible value of f(S). Then print the cardinality of set |S|.
Then print the elements of the set in any order.
If there are multiple optimal sets, you can print any of them.
8 15 3
1
2
10 11
8 30 7
0
5
14 9 28 11 16
Operation represents
the operation of bitwise exclusive OR. In other words, it is the XOR operation.
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; typedef long long int LL; LL L,R,K;
LL ans=0x3f3f3f3f3f3f3f3f; int main()
{
cin>>L>>R>>K;
if(R-L+1<=4)
{
LL m=R-L+1;
LL sig=0;
for(LL i=1;i<(1LL<<m);i++)
{
LL temp=0;
LL wei=0;
LL si=i;
while(si)
{
wei++;
si=si&(si-1);
}
if(wei>K) continue;
for(LL j=0;j<m;j++)
{
if(i&(1LL<<j))
{
temp^=L+j;
}
}
if(temp<ans)
{
ans=temp;
sig=i;
}
}
cout<<ans<<endl;
LL wei=0;
LL tsig=sig;
while(tsig)
{
wei++;
tsig=tsig&(tsig-1);
}
cout<<wei<<endl;
for(LL i=0;i<m;i++)
{
if(sig&(1<<i))
{
cout<<L+i<<" ";
}
}
cout<<endl;
}
else
{
if(K==1)
{
cout<<L<<endl;
cout<<1<<endl;
cout<<L<<endl;
}
else if(K==2)
{
if(L%2) L++;
cout<<1<<endl;
cout<<2<<endl;
cout<<L<<" "<<L+1<<endl;
}
else if(K==3)
{
bool flag=false; LL mx=3,mi=1;
while(mx<=R)
{
if(mi>=L)
{
flag=true;
cout<<0<<endl<<3<<endl;
cout<<mx<<" "<<mx-1<<" "<<mi<<endl;
break;
} mx<<=1LL;
mi<<=1LL; mi++;
} if(flag==false)
{
if(L%2) L++;
cout<<1<<endl;
cout<<2<<endl;
cout<<L<<" "<<L+1<<endl;
}
}
else
{
cout<<0<<endl;
cout<<4<<endl;
if(L%2) L++;
cout<<L<<" "<<L+1<<" "<<L+2<<" "<<L+3<<endl;
}
}
return 0;
}
Codeforces 460 D. Little Victor and Set的更多相关文章
- Codeforces 460 DE 两道题
D Little Victor and Set 题目链接 构造的好题.表示是看了题解才会做的. 假如[l,r]长度不超过4,直接暴力就行了. 假如[l,r]长度大于等于5,那么如果k = 1,显然答案 ...
- codeforces 460D:Little Victor and Set
Description Little Victor adores the sets theory. Let us remind you that a set is a group of numbers ...
- Codeforces 460D Little Victor and Set(看题解)
Little Victor and Set 其他都很好求, 只有k == 3的时候很难受.. 我们找到第一个不大于l的 t, 答案为 l, 3 * t, (3 * t) ^ l 感觉好像是对的, 感觉 ...
- Codeforces Round #483 (Div. 2) [Thanks, Botan Investments and Victor Shaburov!]
题目链接:http://codeforces.com/contest/984 A. Game time limit per test:2 seconds memory limit per test:5 ...
- Codeforces 460D. Little Victor and Set
D. Little Victor and Set time limit per test:1 second memory limit per test:256 megabytes input:stan ...
- Codeforces Round #460 (Div. 2) E. Congruence Equation (CRT+数论)
题目链接: http://codeforces.com/problemset/problem/919/E 题意: 让你求满足 \(na^n\equiv b \pmod p\) 的 \(n\) 的个数. ...
- Codeforces 460D Little Victor and Set --分类讨论+构造
题意:从区间[L,R]中选取不多于k个数,使这些数异或和尽量小,输出最小异或和以及选取的那些数. 解法:分类讨论. 设选取k个数. 1. k=4的时候如果区间长度>=4且L是偶数,那么可以构造四 ...
- codeforces 460D Little Victor and Set(构造、枚举)
最近的CF几乎都没打,感觉挺水的一个题,不过自己仿佛状态不在,看题解才知道做法. 输入l, r, k (1 ≤ l ≤ r ≤ 1012; 1 ≤ k ≤ min(106, r - l + 1)). ...
- Codeforces Round #460 D. Karen and Cards
Description Karen just got home from the supermarket, and is getting ready to go to sleep. After tak ...
随机推荐
- android 博客列表
1. Hongyang http://blog.csdn.net/lmj623565791/article/details/37970961
- Splunk 会议回想: 大数据的关键是机器学习
作者 Jonathan Allen ,译者 张晓鹏 Splunk的用户大会已经接近尾声.三天时间的会议里,共进行了160多个主题研讨.涵盖了从安全.运营到商业智能.甚至包含物联网,会议中一遍又一遍出现 ...
- Openfiler 之Linux 安装ISCSI initiator和自动挂载
OPENFILER做TARGET,RED HAT做客户端,如果默认没有安装ISCSI initiator的话,可以在光盘上找到RPM包直接安装.service iscsi start,启动服务,ser ...
- 利用pandas进行数据分析之三:DataFrame与Series基本功能
未经同意请勿转载http://www.cnblogs.com/smallcrystal/ 前文已经详细介绍DataFrame与Series两种数据结构,下面介绍DataFrame与Series的数据基 ...
- Ant 编译项目资源不足
http://www.cnblogs.com/interboy/archive/2008/07/15/1243265.html今天用ant编译项目出现 [javac] 系统资源不足.的错误,如下 Bu ...
- 通过Spring使用远程访问和web服务
http://docs.huihoo.com/spring/zh-cn/remoting.html Spring2 提供的remote包学习笔记
- HTTP请求报文属性详解
HTTP请求报文组成:请求行+请求头+请求体 注意:请求体和URL都可以传递请求参数. 常见请求头属性: 1.Accept 作用:浏览器客户端用来告诉服务端能接受什么类型的响应. 例如: Acce ...
- mvc模型绑定问题
public void AddDesk(x_s_desk x_s_desk) 绑定的到 public void AddDesk(x_s_desk desk) 绑定不到 目前不知道原因 且仅有部分模型需 ...
- OUTLOOK之不能直接发送邮件的Mapi错误解决方法
近期在从office2010直接升级到2013,发现右键文件不能发送到邮件了,同一时候在word文档里.也不能作为附件发送到邮件了. 提示错误是: Mapi Failure - "Unspe ...
- McCabe环路复杂度计算方法
环路复杂度用来定量度量程序的逻辑复杂度.以McCabe方法来表示. 在程序控制流程图中,节点是程序中代码的最小单元,边代表节点间的程序流.一个有e条边和n个节点的流程图F,可以用下述3种方法中的任何一 ...