题意:给你一个数字n,有两种操作:减1或乘2,问最多经过几次操作能变成m: 随后发篇随笔普及下memset函数的初始化问题.自己也是涨了好多姿势. 代码 #include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #define INF 0x7fffffff; using namespace std; ], vis[]; int dp(int n, int m) { ) re…
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 blue button and a display s…
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 blue button and a display showing…
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 blue button and a display showing…
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 blue button and a display showing…
题意:有两个正整数\(n\)和\(m\),每次操作可以使\(n*=2\)或者\(n-=1\),问最少操作多少次使得\(n=m\). 题解:首先,若\(n\ge m\),直接输出\(n-m\),若\(2*n>=m\),分\(m\)的奇偶判断一下,如果是奇数就输出\(n-(m+1)/2+2\),是偶数就输出\(n-m/2+1\).否则我们就需要用dp来求解,因为是求最小值,所以先初始化将所有值设为\(INF\),\(dp[i]\)表示从\(n\)到\(m\)的操作次数最少的最优解,首先需要更新\([…
水 A. Pangram /* 水题 */ #include <cstdio> #include <iostream> #include <algorithm> #include <map> #include <set> #include <cmath> #include <string> #include <cstring> using namespace std; int main(void) { //fr…
题意:如题定义的函数,取最大值的数量有多少? 结论只猜对了一半. 首先,如果只有一个元素结果肯定是1.否则.s串中元素数量分别记为a,t,c,g.设另一个串t中数量为a',t',c',g'.那么,固定s串,移动t串时,增加的量为p=a*a'+t*t'+c*c'+g*g'.注意a'+t'+c'+g'是等于串长,那么减少a,t,c,g中最少的对应的那个a',t',c',g',增加到最大的那个上,p值是上升的.而且如果a==t那么a'和t'的数量互换是不影响p值的.因此结论是这种情况下,t串可随意 放…
C. DNA Alignment time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vasya became interested in bioinformatics. He's going to write an article about similar cyclic DNA sequences, so he invente…
A. Pangram time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at…