
借光光YZC的福气(今天拿到Rank1),本来还可以更好的,前面吃M去了,ABC都很晚切,而且异常兴奋,结果WA了好多发
Describe:我们都知道,Home W的数学最厉害了。有一天,他又开始开动脑筋了,他想:“为什么数字总是要从1排列到n呢?”于是,Home W开始研究自己排列数字的方法。首先,他写下了1-n中所有的奇数(按照升序排列),然后他又写下了1-n中所有的偶数(按照升序排列),那么问题来了,在这样的排列方式下第k个数是什么呢?
Solution:第一发getLL 结果int n。。。推推公式,奇数有x=(n+1)/2个,x<=k→k*2-1,k-=x,剩下是偶数k*2
Code:
// <A.cpp> - Sun Oct 9 19:01:04 2016
// This file is made by YJinpeng,created by XuYike‘s black technology automatically.
// Copyright (C) 2016 ChangJun High School, Inc.
// I don‘t know what this program is.
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define MOD 1000000007
#define INF 1e9
#define IN inline
#define RG register
using namespace std;
typedef long long LL;
typedef long double LB;
const int MAXN=100010;
const int MAXM=100010;
inline int max(int &x,int &y) {return x>y?x:y;}
inline int min(int &x,int &y) {return x<y?x:y;}
inline LL gi() {
register LL w=0,q=0;register char ch=getchar();
while((ch<‘0‘||ch>‘9‘)&&ch!=‘-‘)ch=getchar();
if(ch==‘-‘)q=1,ch=getchar();
while(ch>=‘0‘&&ch<=‘9‘)w=w*10+ch-‘0‘,ch=getchar();
return q?-w:w;
}
int main()
{
freopen("A.in","r",stdin);
freopen("A.out","w",stdout);
LL n=gi(),k=gi();
if(k<=(n+1)/2){
cout<<2*k-1;return 0;
}
k-=(n+1)/2;cout<<k*2;
return 0;
}
原文:http://www.cnblogs.com/YJinpeng/p/5944174.html