A. Remove a Progression
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
You have a list of numbers from 1 to n written from left to right on the blackboard.
You perform an algorithm consisting of several steps (steps are 1-indexed). On the i-th step you wipe the i-th number (considering only remaining numbers). You wipe the whole number (not one digit).
When there are less than i numbers remaining, you stop your algorithm.
Now you wonder: what is the value of the x-th remaining number after the algorithm is stopped?
Input
The first line contains one integer T (1≤T≤100) — the number of queries. The next T lines contain queries — one per line. All queries are independent.
Each line contains two space-separated integers n and x (1≤x<n≤109) — the length of the list and the position we wonder about. It’s guaranteed that after the algorithm ends, the list will still contain at least x numbers.
Output
Print T integers (one per query) — the values of the x-th number after performing the algorithm for the corresponding queries.
Example
inputCopy
3
3 1
4 2
69 6
outputCopy
2
4
12
发现长时间没做思路题脑子真的钝化了,这道题竟然当时没看出来,也可能是当时有点累吧。。。。。。
题目大意:告诉你一个数n,然后第一次拿走第1个数,然后剩下的数中拿走第2个,然后剩下的数拿第3个,直到拿到不能拿为止,比如1 2 3 4 5 6 7 8 9 10
第一次拿走第一个数(1)变成 2 3 4 5 6 7 8 9 10
第二次拿走第二个数(3)变成2 4 5 6 7 8 9 10
第三次拿走第三个数(5)变成2 4 6 7 8 9 10
第四次拿走第四个数(7)变成2 4 6 8 9 10
第五次拿走第五个数(9)变成2 4 6 8 10
第六次没法拿了,因为就5个数
思路:举了这么多例子也能发现规律了,就是不论n是多少,他们的第几个数都是相同的,因为剩下来的都是2的倍数,2,4,6,8,10,12。。。。。 所以答案就是2*n
#include <iostream>
#include<algorithm>
#include<string.h>
#include<stdio.h>
using namespace std;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int m,n;
scanf("%d%d",&m,&n);
printf("%d\n",n*2);
}
return 0;
}