zoukankan      html  css  js  c++  java
  • 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/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=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    //**************************************************************************************
    
    int main()
    {
        ll n=read(),k=read();
        if(n%2==1)
        {
            if(k<=n/2+1)
                printf("%lld",k*2-1);
            else
                printf("%lld",(k-n/2-1)*2);
        }
        else
        {
            if(k<=n/2)
                printf("%lld",k*2-1);
            else
                printf("%lld",(k-n/2)*2);
        }
    }
  • 相关阅读:
    warning: LF will be replaced by CRLF in ***. The file will have its original line endings in your working directory.
    GitHub出现Permissiondenied (publickey).
    浏览器编辑web页面的方法
    用scikit-learn进行LDA降维
    支持向量机原理(二) 线性支持向量机的软间隔最大化模型
    奇异值分解(SVD)原理与在降维中的应用
    scikit-learn K近邻法类库使用小结
    矩阵分解在协同过滤推荐算法中的应用
    精确率与召回率,RoC曲线与PR曲线
    异常点检测算法小结
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4574707.html
Copyright © 2011-2022 走看看