博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces 460 D. Little Victor and Set
阅读量:6854 次
发布时间:2019-06-26

本文共 2881 字,大约阅读时间需要 9 分钟。

暴力+构造

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 xy 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 xy 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.

D. Little Victor and Set
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
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; value  must be as small as possible.

Help Victor find the described set.

Input

The first line contains three space-separated integers l, r, k (1 ≤ l ≤ r ≤ 1012; 1 ≤ k ≤ min(106, r - l + 1)).

Output

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.

Sample test(s)
input
8 15 3
output
1210 11
input
8 30 7
output
0514 9 28 11 16
Note

Operation  represents the operation of bitwise exclusive OR. In other words, it is the XOR operation.

#include 
#include
#include
#include
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<
K) continue; for(LL j=0;j
=L) { flag=true; cout<<0<
<<3<

转载地址:http://jyyyl.baihongyu.com/

你可能感兴趣的文章
使用UIPickerView显示数据
查看>>
java代码继承基础
查看>>
java继承实例基础
查看>>
数据库增删改查梳理
查看>>
linux下检测每个进程占用swap大小
查看>>
[转] 编译输出文件的区别
查看>>
Java MyBatis 插入数据库返回主键--insertSelective这样就不用每次到数据库里面查询了...
查看>>
springboot集成redis操作
查看>>
x64 QWORD Xor shellcode encoder
查看>>
大数据之mapreduce小实战
查看>>
Elasticsearch(二)
查看>>
一步一步学linq to sql(九)其他补充
查看>>
windows service and process 的关系
查看>>
转 Oracle 12C 之 CDB/PDB用户的创建与对象管理
查看>>
iOS常用设置界面跳转
查看>>
智能家居之红外遥控---手机万能红外遥控器
查看>>
取消input默认样式
查看>>
递增链表的插入
查看>>
判断节点包含
查看>>
springcloud(十七):服务网关 Spring Cloud GateWay 熔断、限流、重试
查看>>