Codeforces 318A Even Odds

原创 2015年07月07日 11:12:33

题目链接 :http://codeforces.com/problemset/problem/318/A

A. Even Odds

time limit per test:1 second

memory limit per test:256 megabytes

input:standard input

output:standard output

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 test(s)

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.

一开始看到题目以为要用到大数相加,后来发现找找数学规律就好。

#include<iostream>
typedef __int64 tt;
using namespace std;

int main()
{
    tt n,k;
    while(cin>>n>>k){
        if(n % 2 == 0)
        {
            if(k <= n/2)  cout <<2 *k -1;

                          else  cout << 2 *( k - n / 2);
        }
        else
        {
            if(k <= n / 2 + 1) cout << 2 *k -1;

               else cout<< 2 *( k - n / 2 - 1);
        } 

        cout<<endl ;

    }
    return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。

【打CF,学算法——一星级】CodeForces 318A (水题)

题目链接: 题面: C - Even Odds Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d ...

Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 1)

A. Bear and Poker time limit per test 2 seconds memory limit per test 256 megabytes ...

Codeforces Round #318-(B. Bear and Three Musketeers)

这道题做的时候还剩下30多分钟了,于是有点慌。。。果然心理素质还是有待提高,这么水的题都没有过):导致又掉rating了。。。 题意: 现在给你n个人,m个询问,然后接下来m行告诉你a与b是相互认...

Codeforces Round #318 vp

codeforce vp
  • oHorace
  • oHorace
  • 2016年08月19日 18:15
  • 106

Codeforces Round #318 (Div. 2) B. Bear and Three Musketeers 位运算压缩

题意:有n个人,m组关系。现在想要从这n个人中选3个人。这3个人必须满足的条件:1)这3个人必须相互认识 2)这3个人的识别度的总和最小(一个人的识别度为:除了另外两人认识的人的数,三个人的识别度相加...
  • CHCXCHC
  • CHCXCHC
  • 2015年09月09日 22:50
  • 261

codeforces#318ABCD

点击查看题目 A#include #include #include #include #include #include #include #include #include #...

Codeforces Round #318(ABCD)

A题意: 每次操作可以让第一个数字加1,第一个数字之后的数字减1,问你最少变换多少可以使得第一个数字大于后面所有数字。 解析: 先保存下所有的数字,以及该数字出现的个数。 直接用map,...

Codeforces 318 div2.D Bear and Blocks(dp,贪心)

题目: D. Bear and Blocks time limit per test 1 second memory limit per test ...

【周赛】第一周周赛——欢迎16级的新同学题解(题目出自codeforces 318A,546A,431C,665E,HDU 4104)

A题: A题题目链接 A题题目描述: Home W的数学 TimeLimit:1000MS  MemoryLimit:256MB 64-bit integer IO format:%I64...

Codeforces Round #318 (Div. 2)

思路:最暴力的想法,用一个三重循环去遍历,这道题给出的时间是2秒,而且cf的服务器肯定很好,所以时间上应该是没有压力的,但我心里一直没底,总感觉会超时。 在这里,看了大牛们的代码,学了一个新思路,对于...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Codeforces 318A Even Odds
举报原因:
原因补充:

(最多只允许输入30个字)