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 ;
}

Codeforces 912A/B的更多相关文章

  1. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  2. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  3. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  4. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  5. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  6. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

  7. CodeForces - 261B Maxim and Restaurant

    http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...

  8. CodeForces - 696B Puzzles

    http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...

  9. CodeForces - 148D Bag of mice

    http://codeforces.com/problemset/problem/148/D 题目大意: 原来袋子里有w只白鼠和b只黑鼠 龙和王妃轮流从袋子里抓老鼠.谁先抓到白色老鼠谁就赢. 王妃每次 ...

随机推荐

  1. alsa 用户空间编程【转】

    本文转载自:http://blog.csdn.net/sjin_1314/article/details/12872581 /**alsa play test *ALSA用户空间编译,ALSA驱动的声 ...

  2. POJ 2728(最优比率生成树+01规划)

                                                                                                    Dese ...

  3. k-means 聚类前的数据分析

    原始数据 Say you are given a data set where each observed example has a set of features, but has nolabel ...

  4. TCP打开文件传输(客户端code)

    #include <stdio.h>#include <stdlib.h>#include <arpa/inet.h>#include <sys/types. ...

  5. es6入门6--数组拓展运算符,Array.from()基本用法

    本文只是作为ES6入门第九章学习笔记,在整理知识点的同时,会加入部分个人思考与解答,若想知道更详细的介绍,还请阅读阮一峰大神的ES6入门 一.拓展运算符 ES6中新增了拓展运算(...)三个点,它的作 ...

  6. GStreamer系列 - 基本介绍

    什么是Gstreamer? Gstreamer是一个支持Windows,Linux,Android, iOS的跨平台的多媒体框架,应用程序可以通过管道(Pipeline)的方式,将多媒体处理的各个步骤 ...

  7. C#将文件压缩成一个文件流,供前端下载

    直接上代码供大家参考... 前端页面就是一个下载的Button.. <body> <form id="form1" runat="server" ...

  8. Spring Boot (5) Spring Boot配置详解

    application.properties application.properties是spring boot默认的配置文件,spring boot默认会在以下两个路径搜索并加载这个文件 src\ ...

  9. 2018.10.9 上线发现elasticsearch写入速度超级慢,原来罪魁祸首是阿里云服务的OSS的锅

    问题描述: 按照项目计划,今天上线部署日志系统(收集线上的所有日志,便于问题排查). 运维按照以前的部署过程,部署elasticsearch,部署结束之后,通过x-pack的monitor发现elas ...

  10. CSS制作简单loading动画

    曾经以为,loading的制作需要一些比较高深的web动画技术,后来发现大多数loading都可以用“障眼法”做出来.比如一个旋转的圆圈,并不都是将gif图放进去,有些就是画个静止图像,然后让它旋转就 ...