A. Tricky Alchemy

传送门:http://codeforces.com/contest/912/problem/A

参考程序如下:

#include <stdio.h>
#include <stdint.h> int main(void)
{
int64_t a, b, x, y, z;
scanf("%I64d%I64d%I64d%I64d%I64d", &a, &b, &x, &y, &z);
int64_t addA = 2LL * x + y - a > ? 2LL * x + y - a: ;
int64_t addB = 3LL * z + y - b > ? 3LL * z + y - b: ;
printf("%I64d\n", addA + addB);
return ;
}

B. New Year's Eve

给定两个整数nk:在1~n中选择至多k个整数,使得其异或和最大。求解这个最大值。

显然,当k=1时,只选择一个整数n,于是答案为n

k>1时,可以考虑异或和可能达到的最大值:将n的所有可改变的二进制位(即最高的‘1’位以下的二进制位)均变为‘1’,这个值就是异或和可能达到的最大值。

S=2b-1,则对于任意自然数a,若a<S,则一定有aÅ(S-a)=S。由于S的二进制位,0~b-1位均为‘1’,于是根据位运算的基本规则,等式显然成立。

于是,当k>1时,设n的最高‘1’位为b-1位,S=2b-1,则可选择两个整数:nS-n(注意,这里n≥2b-1,于是S-n<2b-1n);特别地,当n=S时,只选择一个整数n。于是答案为S

参考程序如下:

#include <stdio.h>
#include <stdint.h> int main(void)
{
int64_t n, k;
scanf("%I64d%I64d", &n, &k);
if (k == ) {
printf("%I64d\n", n);
return ;
}
int bit = ;
for (; n >> bit; bit++);
printf("%I64d\n", (1LL << bit) - );
return ;
}

最新文章

  1. SpringSecurity操作指南-基于Spring、SpringMVC和MyBatis自定义SpringSecurity权限认证规则
  2. JS中this的指向问题
  3. Asp.net GridView控件使用纪要
  4. windows mysql 自动备份的几种方法
  5. HDU5052 Yaoge’s maximum profit(LCT)
  6. 机器人学 —— 机器人感知(Gaussian Model)
  7. NDK(21)JNI的5大正确性缺陷及优化技巧(注意是正确性缺陷)
  8. PHP.3-DIV+CSS标准网页布局准备工作(上)
  9. php前端控制器2
  10. docker 基础命令
  11. Codeforces 895C - Square Subsets 状压DP
  12. 深入剖析Tomcat会话机制
  13. 使用mybatis操作AS400数据库
  14. SQL Server通过BCP进行大批量数据导入导出
  15. np.tile语法
  16. ArgumentException: 已添加了具有相同键的项。
  17. 20165318 预备作业3 Linux安装及学习
  18. Android 的事件传递机制,详解
  19. php PDO操作类
  20. C语言 结构体作为参数和返回值使用

热门文章

  1. Android studio第一次使用配置(三)gradle项目构建
  2. Ext.tree.Panel实现单选,多选
  3. oc35--自定义构造方法
  4. C# SuperWebSocket服务端、客户端学习(三)
  5. hdoj--1518--Square(dfs)
  6. C++ 中的友元(friend)
  7. Error-Java-IJ:Imported project refers to unknown jdks JavaSE-1.7
  8. 操作系统-虚拟机-百科:VM
  9. im4java+GraphicsMagick
  10. BZOJ 1037 生日聚会 DP