整合整数

B - 2 CodeForces - 318A

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到n的所有奇数整数(按升序排列),然后从1到n的所有偶数整数(也按升序排)找出哪个数字将站在位置编号k。
思路:如果k小于n/2;那么就是奇数等于(2k-1);如果大于n/2那么就是偶数为(2(k-2/n))。
代码如下(已AC)

#include<iostream>
using namespace std;
int main()
{
	long long int n, k, x;
	cin >> n >> k;
	if (n % 2 == 0)
		x = n / 2;
	else
		x = n / 2 + 1;
	if (k <= x)
		cout << 2 * k - 1;
	else
		cout << 2 * (k - x);
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
当谈到MySQL的知识点整合时,以下是一些重要的主题和概念: 1. 数据库管理系统(DBMS):MySQL是一种开源的关系型数据库管理系统,用于存储和管理数据。 2. 数据库和表:MySQL允许您创建多个数据库,每个数据库可以包含多个表。表是数据的结构化表示,由列和行组成。 3. 数据类型:MySQL支持多种数据类型,包括整数、浮点数、字符、日期和时间等。选择正确的数据类型可以提高性能和存储效率。 4. SQL语言:结构化查询语言(SQL)是一种用于与数据库进行交互的标准语言。MySQL使用SQL来查询、插入、更新和删除数据。 5. 查询语句:MySQL的SELECT语句用于从表中检索数据。您可以使用WHERE子句对数据进行过滤,使用ORDER BY子句对结果进行排序。 6. 索引:索引是一种数据结构,用于加快数据检索速度。在MySQL中,您可以为表中的列创建索引,以提高查询性能。 7. 关系和关联:MySQL支持关系型数据库模型,其中不同表之间可以建立关系和关联。通过使用JOIN操作,您可以联接多个表以获取相关数据。 8. 数据完整性:MySQL提供了各种机制来确保数据的完整性,包括主键约束、唯一约束、外键约束和检查约束。 9. 事务:事务是一组数据库操作,被视为单个逻辑单元。MySQL使用事务来确保数据的一致性和完整性,并支持ACID属性(原子性、一致性、隔离性和持久性)。 10. 数据库备份和恢复:MySQL允许您创建数据库备份,以防止数据丢失。您可以使用备份文件来恢复数据库到先前的状态。 这只是MySQL的一些基本知识点,但它们可以帮助您开始使用MySQL并理解关系型数据库的基本概念。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值