B - Even Odds
Problem description
Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first n. He writes down the following sequence of numbers: firstly all odd integers from 1 to n (in ascending order), then all even integers from 1 to n (also in ascending order). Help our hero to find out which number will stand at the position number k.
Input
The only line of input contains integers n and k (1 ≤ k ≤ n ≤ 1012).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Output
Print the number that will stand at the position number k after Volodya's manipulations.
Examples
Input
10 3
Output
5
Input
7 7
Output
6
Note
In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5.
解题思路:题目的意思就是输出构造序列n:{1,3,5,...,2,4,6,...,}中的第k个数,简单水过!
AC代码:
#include <bits/stdc++.h>
using namespace std;
int main(){
long long n,k,r;
cin>>n>>k;
if(n%)n++;
n/=;
if(n>=k)r=*k-;
else r=*(k-n);
cout<<r<<endl;
return ;
}
B - Even Odds的更多相关文章
- Codeforces Round #188 (Div. 2) A. Even Odds 水题
A. Even Odds Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/318/problem/ ...
- Project Euler 84:Monopoly odds 大富翁几率
Monopoly odds In the game, Monopoly, the standard board is set up in the following way: ...
- HDU 6382 odds (暴力 + 剪枝优化)
odds Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Subm ...
- codeforces 318 A.Even Odds B.Sereja and Array
A.Even Odds 给你n和k, 把从1到n先排奇数后排偶数排成一个新的序列,输出第k个位置的数. 比如 10 3 拍好后就是 1 3 5 7 9 2 4 6 8 10 第3个数是5. // ...
- Odds calculation required for the python strategy library
Bet Class class strats.Bet(inp)[source] Here is an example of the expected string input on instantia ...
- 从Odds:比值比推导出Logtic分类的算法
在从概率模型推导出逻辑回归算法模型的博文中,我试着从李宏毅老师的课程中讲到的概率模型去推导逻辑分类的算法模型.有幸看到另外一篇博文01 分类算法 - Logistic回归 - Logit函数,我了解到 ...
- A. Odds and Ends(思维)
A. Odds and Ends time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- 广义线性模型|logistics|Odds ratio|最大似然函数|LR|AIC|
广义线性模型 y是分类变量 Link function:将分类变量和数值变量放在一起 使用得到结果0 or 1的概率值来评估选0 or1 函数关系: 正比例函数: logistics函数S型曲线: O ...
- Codeforces 849A:Odds and Ends(思维)
A. Odds and Ends Where do odds begin, and where do they end? Where does hope emerge, and will they e ...
- Even Odds (java)
从1到n的奇数,从1到n之间的偶数,排列在一起,找到第k个数 Input 输入包含 n and k (1 ≤ k ≤ n ≤ 1012). Please, do not use the %lld sp ...
随机推荐
- windows下安装Python-Whl文件
原文链接:http://blog.sciencenet.cn/home.php?mod=space&uid=1181151&do=blog&id=865515 Note1. 整 ...
- brew 安装的.net 运行时提示"Did you mean to run dotnet SDK commands?"
原因未知,但有解决方案 使用 brew cask 安装的.NET Core brew cask install dotnet 结果运行时出现: 解决方案: 下载官方 .pkg 文件安装,顺便卸载掉 b ...
- 修复Thinkphp框架5.0和5.1版本的远程代码执行安全漏洞
由于框架对控制器名没有进行足够的检测会导致在没有开启强制路由的情况下可能的getshell漏洞.最直接的影响为index.php直接被篡改成首页html的内容! 5.0版本 thinkphp/libr ...
- eas之排序接口
KDTable目前本身并不支持排序功能,但提供了排序的接口,用户通过实现该接口(ISortManager)即可实现排序的功能.同时KDTable提供了一个简单实现KDTSortManager,这个类完 ...
- 文件操作(day15)
调用函数可以使用被调用函数动态分配的 存储区 calloc函数也可以动态分配一组连续的 存储区 这个函数可以把所有动态分配的存储区 内容设置成0 为了使用这个函数也需要包含stdlib.h头文件 这个 ...
- IDEA返回上一步
在开发中进入一个方法后想要到原来那行 ctrl+alt+左 回到上一步 ctrl+alt+右 回到下一步
- [pytorch学习]2. 官网60分钟教程摘要
https://pytorch.org/tutorials/beginner/deep_learning_60min_blitz.html 1. Pytorch的基本单元,tensor,本质上和num ...
- Golang - 流程控制
目录 Golang - 流程控制 1. 选择结构 2. 循环结构 3. 跳转语句 Golang - 流程控制 1. 选择结构 if else语句: //package 声明开头表示代码所属包 pack ...
- 3.Linux 系统目录结构
Linux 系统目录结构 登录系统后,在当前命令窗口下输入命令可以查看我们系统的默认文件列表: ls / 你会看到如下图所示: 树状目录结构: 以下是对这些目录的解释: /bin:bin是Bina ...
- BZOJ 1500 Luogu P2042 [NOI2005] 维护数列 (Splay)
手动博客搬家: 本文发表于20180825 00:34:49, 原地址https://blog.csdn.net/suncongbo/article/details/82027387 题目链接: (l ...