CF 520 B. Two Buttons(bfs)】的更多相关文章

/*题意:一个数,就是输入的第一个数,让它变成第二个数最少用几步.可以点红色按钮,蓝色按钮来改变数字,红色:*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 s…
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…
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…
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…
题目: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<<…
题目大意: 给定n m 第一行有n个数 第二行有m个数 接下来n行每行m列 有 = < > 位于 i j 的符号表示 第一行第i个数与第二行第j个数的大小关系 1.将n+m个数 当做按顺序编号的点 则第二行的数是编号为 n+j 的点 2.先处理=的数 将所有=的数指向同一个父亲 3.再处理不是=的数 找到两者的父亲 如果父亲相同说明两者= 与目前处理的情况相悖 无解 否则 按由小到大的关系在两者(的父亲)间连单向边(小连向大) 此时较大的点入度+1 4.此时查看所有点的入度 入度为0 说明这个…
(一).首先.让我们认识一下最基本普通的alert()弹出框!(改变alert()提示弹出框的样式) 我们在写html或是jsp页面的时候,谁都不希望自己精心设计,且非常美观的页面颜色布局被破坏掉吧!但是恰恰不巧的是jQuery自带的alert()弹出提示框就会影响这一美观: 在不同的浏览器中,alert()方法,弹出的样式真的很难看:所以为了解决这一方法,我门可以自定义自己的alert(),让我们来看看这些代码吧! function myalert(str){ var msgw,msgh,bo…
http://codeforces.com/contest/520/problem/B Two Buttons 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 clicking the red button, device multipl…