BZOJ1621: [Usaco2008 Open]Roads Around The Farm分岔路口
来源:互联网 发布:淘宝西台美肤真假 知乎 编辑:程序博客网 时间:2024/04/28 20:25
Description
约翰的N(1≤N≤1,000,000,000)只奶牛要出发去探索牧场四周的土地.她们将沿着一条路走,一直走到三岔路口(可以认为所有的路口都是这样的).这时候,这一群奶牛可能会分成两群,分别沿着接下来的两条路继续走.如果她们再次走到三岔路口,那么仍有可能继续分裂成两群继续走. 奶牛的分裂方式十分古怪:如果这一群奶牛可以精确地分成两部分,这两部分的牛数恰好相差K(1≤K≤1000),那么在三岔路口牛群就会分裂.否则,牛群不会分裂,她们都将在这里待下去,平静地吃草. 请计算,最终将会有多少群奶牛在平静地吃草.
Input
两个整数N和K.
Output
最后的牛群数.
Sample Input
6 2
INPUT DETAILS:
There are 6 cows and the difference in group sizes is 2.
INPUT DETAILS:
There are 6 cows and the difference in group sizes is 2.
Sample Output
3
OUTPUT DETAILS:
There are 3 final groups (with 2, 1, and 3 cows in them).
6
/ \
2 4
/ \
1 3
OUTPUT DETAILS:
There are 3 final groups (with 2, 1, and 3 cows in them).
6
/ \
2 4
/ \
1 3
HINT
6只奶牛先分成2只和4只.4只奶牛又分成1只和3只.最后有三群奶牛.
题解:
直接模拟就好,没什么好说的吧……队列实现,或者递归实现,我用的队列
#include <iostream>#include <cstdio>#include <algorithm>#include <queue>using namespace std;queue <int > Q;int main(int argc, char *argv[]){ int n,k,t,d=0; scanf("%d%d",&n,&k); Q.push(n); while(!Q.empty()) { t=Q.front(); if(t>k&&(t-k)%2==0) Q.push((t-k)/2),Q.push((t-k)/2+k); else d++; Q.pop(); } printf("%d\n",d); return 0;}
0 0
- [BZOJ1621][Usaco2008 Open]Roads Around The Farm分岔路口
- BZOJ1621: [Usaco2008 Open]Roads Around The Farm分岔路口
- BZOJ 1621: [Usaco2008 Open]Roads Around The Farm分岔路口
- BZOJ 1621: [Usaco2008 Open]Roads Around The Farm分岔路口
- 【BZOJ 1621】 [Usaco2008 Open]Roads Around The Farm分岔路口
- BZOJ-1621-[Usaco2008 Open]Roads Around The Farm分岔路口
- BZOJ 1621: [Usaco2008 Open]Roads Around The Farm分岔路口
- bzoj1621【Usaco2008 Open】Roads Around The Farm
- BZOJ 1621 [Usaco2008 Open]Roads Around The Farm分岔路口 模拟
- 1621: [Usaco2008 Open]Roads Around The Farm分岔路口(记忆化搜索)
- [Usaco08Open] Roads Around The Farm
- luogu2907 [USACO08OPEN]农场周围的道路Roads Around The Farm
- [Usaco2008 Open]Crisis on the Farm 牧场危机
- BZOJ 1605 [Usaco2008 Open]Crisis on the Farm 牧场危机 DP
- 麻烦的DP-BZOJ-1605-[Usaco2008 Open]Crisis on the Farm 牧场危机
- bzoj 1605: [Usaco2008 Open]Crisis on the Farm 牧场危机(DP)
- 走上人生的分岔路口
- [Usaco2008 Dec]Trick or Treat on the Farm 采集糖果
- 平面的投影变换(1)——什么是投影变换?
- hdoj 1698 Just a Hook【线段树】
- iframe dom的控制方法。
- 安装及配置 Mac 上的 Rime 输入法——鼠鬚管 (Squirrel)(也适用于小狼豪)
- linux shell脚本 变量给变量赋值
- BZOJ1621: [Usaco2008 Open]Roads Around The Farm分岔路口
- js获取div内容
- Kth Largest Element in an Array
- AngularJS的模态框
- 欢迎使用CSDN-markdown编辑器
- 那些年踩过的坑 android开发致命的错误合集
- java maven web项目如何使用jetty调试
- 定制小狼豪(五笔+拼音)输入法
- 搭建Hadoop和Hive客户端