Codeforces Round #188 (Div. 2) / 318A Even Odds(简单数学)
2013-08-13 17:43
302 查看
A. Even Odds
http://codeforces.com/problemset/problem/318/A
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 %I64dspecifier.
Output
Print the number that will stand at the position number k after Volodya's manipulations.
Sample test(s)
input
output
input
output
水。
完整代码:
http://codeforces.com/problemset/problem/318/A
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 %I64dspecifier.
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
水。
完整代码:
/*30ms,0KB*/ #include<cstdio> int main() { __int64 n, k; scanf("%I64d%I64d", &n, &k); if (n & 1) { if (k > (n >> 1) + 1) { k -= (n >> 1) + 1; printf("%I64d", k << 1); } else printf("%I64d", (k << 1) - 1); } else { if (k > (n >> 1)) { k -= n >> 1; printf("%I64d", k << 1); } else printf("%I64d", (k << 1) - 1); } return 0; }
相关文章推荐
- Codeforces Round #327 (Div. 2) (A. Wizards' Duel 简单数学)
- Codeforces Round #387 (Div. 2)A. Display Size(简单数学)
- Codeforces Round #426 (Div. 2) C. The Meaningless Game(简单数学)
- SGU - 105 - Div 3 (简单数学题!)
- codeforces #230 (Div. 2) B(简单数学)
- Codeforces Round #262 (Div. 2)460A. Vasya and Socks(简单数学题)
- Codeforces #262 (Div. 2) B. Little Dima and Equation(数学:简单)
- Codeforces Round #262 (Div. 2)460A. Vasya and Socks(简单数学题)
- Codeforces Round #239 (Div. 2) C. Triangle(简单数学+暴力)
- Codeforces Beta Round #92 (Div. 2) / 124A The number of positions (简单数学)
- 最简单的方法解决div被select遮挡的问题
- CF #278 (Div. 2) B.(暴力枚举+推导公式+数学构造)
- POJ 1003(Hangover 简单数学) 解题报告
- 一个DIV+CSS代码布局的简单导航条
- FJUT 3101 Home_W的简单问题3 数学 因子和问题
- ACM 进阶学习第一课----简单数学问题之同余相关
- 数学之美 简单笔记
- Codeforces Round #360 (Div. 2) D 数学题
- 洛谷 1403——[AHOI2005]约数研究(简单数学问题)
- uva - 11636 - Hello World!(简单数学)