cf.295.B Two Buttons (bfs)】的更多相关文章

 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…
/*题意:一个数,就是输入的第一个数,让它变成第二个数最少用几步.可以点红色按钮,蓝色按钮来改变数字,红色:*2,蓝色:-1,如果变成负数,就变成原来的数.CF 520 B. Two Buttons思路:当然是*2可以掠过的步数更少啦,如果n是输入,m是输出. 如果n大于m,不能使用红色按钮,很容易看出,步数就是n-m. 如果n比m小,如果m是偶数的话,m/2,如果m是奇数,m+1,这样一直循环判断n是不是还比m小,不符合就跳出循环,进入第一个如果.*/ /*正向BFS #include<ios…
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 so…
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 进行两种操作 减一或者乘二,操作过程中 n 必须保证非负,问使 n 变为 m 至少需要几步操作. 这是我练水题的时候做到的,题目不难,只是我 bfs 一直没怎么用过比较不熟练,RE 了两发,就整理了这题. 首先,若 n==m ,那么步骤数就是 0 ,而若 n > m ,n 进行乘二的操作就会使 n 离 m 更远,所以必然是一直减一,于是步骤数就是 n -m : 若 n < m , 此时由于中间的步骤并不确定,就可以用 bfs 搜索,但是由于使用数组记录某个…
1.CF #375 (Div. 2)  D. Lakes in Berland 2.总结:麻烦的bfs,但其实很水.. 3.题意:n*m的陆地与水泽,水泽在边界表示连通海洋.最后要剩k个湖,总要填掉多少个湖,然后输出. #include<bits/stdc++.h> #define F(i,a,b) for (int i=a;i<b;i++) #define FF(i,a,b) for (int i=a;i<=b;i++) #define mes(a,b) memset(a,b,s…
题目:http://codeforces.com/contest/986/problem/A 如果从每个村庄开始bfs找货物,会超时. 发现k较小.那就从货物开始bfs,给村庄赋上dis[ 该货物 ]. 但这样还是n^2.考虑有相同货物的村庄,其实可以一起bfs.就是多源bfs.这样就是n*k的了. 多源bfs就是把一些起始点的dis全赋了初值0,然后都放进队列里,之后正常bfs. #include<iostream> #include<cstdio> #include<cs…
来两遍 $BFS,$ 都贪心一下即可. #include <bits/stdc++.h> #define maxn 300009 using namespace std; void setIO(string s) { string in=s+".in"; freopen(in.c_str(),"r",stdin); } queue<int>Q; int n,m,s,edges,nn=0; int hd[maxn],to[maxn<<…
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 invented a…
题目大意: 给定n m 第一行有n个数 第二行有m个数 接下来n行每行m列 有 = < > 位于 i j 的符号表示 第一行第i个数与第二行第j个数的大小关系 1.将n+m个数 当做按顺序编号的点 则第二行的数是编号为 n+j 的点 2.先处理=的数 将所有=的数指向同一个父亲 3.再处理不是=的数 找到两者的父亲 如果父亲相同说明两者= 与目前处理的情况相悖 无解 否则 按由小到大的关系在两者(的父亲)间连单向边(小连向大) 此时较大的点入度+1 4.此时查看所有点的入度 入度为0 说明这个…