CodeForces 520B Two Buttons】的更多相关文章

 Two Buttons time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing s…
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Description Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After click…
题目链接 \(Description\) 给定两个数\(n,m\),每次可以使\(n\)减一或使\(n\)乘2.求最少需要多少次可以使\(n\)等于\(m\). \(Solution\) 暴力连边BFS或者DP都行,都是O(n)的.有更优的做法. 过程是可逆的,我们考虑m变成n,有两种操作:1是m+=1:2是当m为偶数时,m/=2. 要用最少的次数使得m<=n. 因为m加两次再除以二和先除以二再加一次得到的结果是一样的,即能除就不加.这样就O(logn)解决了. 正推n到m好像推不出性质啊..正…
题目链接:http://codeforces.com/problemset/problem/520/B 题意 给出两个数n和m,n每次只能进行乘2或者减1的操作,问n至少经过多少次变换后能变成m 思路 在百度之前用了各种方法,dfs,递推什么的能用的全用了,最后都WA在了第七组 百度了一下,看到了大佬们的代码震精了!!!竟然只有一行!! 用逆推,把从n变成m转换成从m变成n. 如果m是偶数那么m一定是通过上一步乘2的操作变来的,如果是奇数,那么一定是通过上一步减一变来的.最后当m小于n的时候,停…
[题目链接]:http://codeforces.com/contest/520/problem/B [题意] 给你一个数n; 对它进行乘2操作,或者是-1操作; 然后问你到达m需要的步骤数; [题解] 操作的过程中; 可能会大于m吧: 也不知道是多少倍; 但也没事,不差那一点时间. bfs [完整代码] #include <bits/stdc++.h> using namespace std; #define lson l,m,rt<<1 #define rson m+1,r,r…
http://codeforces.com/problemset/problem/520/B B. Two Buttons time limit per test 2 seconds memory limit per test 256 megabytes input:standard input output:standard output Vasya has found a strange device. On the front panel of a device there are: a…
Manao is trying to open a rather challenging lock. The lock has n buttons on it and to open it, you should press the buttons in a certain order to open the lock. When you push some button, it either stays pressed into the lock (that means that you've…
[CF简单介绍] 提交链接:Two Buttons 题面: B. Two Buttons time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vasya has found a strange device. On the front panel of a device there are: a red button, a blu…
J - Two Buttons Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 520B Description Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button a…
这次的题思维都很强,等之后的考试结束会集中精力重新训练一些思维题. A - A simple question CodeForces - 520B 思路: 直接看的话,很容易发现如果 \(n >= m\) 的话 \(sum = n - m\) 即可,但反过来其实 \(m\) 推导 \(n\) 更简单(WA几发后才发现..) 如果 \(m\) 为偶数的话 缩小一半,不然的话先变为偶数再除以2.这样一定能变为 \(n\) void solve() { int n, m; cin >> n &…