A. Even Odds

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/318/problem/A

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.

Sample Input

10 3

Sample Output

5

HINT

题意

给你n,然后把这些数按照先奇数和后偶数排序之后,输出第k个

题解:

很明显这是一道不是输出k*2+1就是输出k*2的答案

我们只要自己出几个无聊的数据测测就好了

代码:

#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
#define maxn 2000001
#define mod 10007
#define eps 1e-9
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************** int main()
{
ll n=read(),k=read();
if(n%==)
{
if(k<=n/+)
printf("%lld",k*-);
else
printf("%lld",(k-n/-)*);
}
else
{
if(k<=n/)
printf("%lld",k*-);
else
printf("%lld",(k-n/)*);
}
}

最新文章

  1. .Net组件程序设计之异步调用
  2. IOS 更改百度地图的定位图片
  3. js闭包,匿名函数概念
  4. 《Continuous Delivery》 Notes 1: The problem of delivering software
  5. Vagrant error: Your VM has become inaccessible.
  6. 15款增强web体验的Javascript库
  7. yum install 与 yum groupinstall 的区别
  8. ADO.NET 快速入门(十三):使用 OLE DB 检索数据
  9. python 自动化之路 day 01.1 数据类型
  10. [wikioi]最长严格上升子序列
  11. hibernate - 何时关闭数据库
  12. OD: Shellcode / Exploit &amp; DLL Trampolining
  13. 字符通向字节流的桥梁---- OutputStreamWriter
  14. Python基础篇-day5
  15. Unity C# 多态 委托 事件 匿名委托 Lambda表达式 观察者模式 .NET 框架中的委托和事件
  16. Linux-共享内存通信
  17. 代码混淆工具——Virbox Protector Standalone
  18. pytorch实现autoencoder
  19. 第三周C++小结
  20. bzoj 4631: 踩气球 线段树合并

热门文章

  1. windows创建虚拟界面
  2. PySpark操作HBase时设置scan参数
  3. ajax 留言板
  4. Hadoop HDFS概念学习系列之分布式文件管理系统(二十五)
  5. Spark RDD概念学习系列之为什么会引入RDD?(一)
  6. poj 2594 Treasure Exploration(最小路径覆盖+闭包传递)
  7. POJ 2774 Long Long Message (后缀数组模板)
  8. Excel合并单元格数据
  9. UITextfiled子视图被剪切
  10. spring mvc学习(一)入门实例