1621: [Usaco2008 Open]Roads Around The Farm分岔路口

Time Limit: 5 Sec  Memory Limit: 64 MB
Submit: 521  Solved: 380
[Submit][Status]

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.

Sample Output

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只.最后有三群奶牛.

Source

 
题解:
模拟一下即可
代码:

 #include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<queue>
#define inf 1000000000
#define maxn 300+10
#define maxm 500+100
#define ll long long
using namespace std;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}
return x*f;
}
int n,k,ans=;
void dfs(int x)
{
if(x-k<||((x&)!=(k&)))ans++;
else
{
int y=(x-k)>>;dfs(y);y=x-y;dfs(y);
}
}
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
n=read();k=read();
dfs(n);
printf("%d\n",ans);
return ;
}

BZOJ1621: [Usaco2008 Open]Roads Around The Farm分岔路口的更多相关文章

  1. BZOJ 1621: [Usaco2008 Open]Roads Around The Farm分岔路口

    题目 1621: [Usaco2008 Open]Roads Around The Farm分岔路口 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 56 ...

  2. 【BZOJ】1621: [Usaco2008 Open]Roads Around The Farm分岔路口(dfs)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1621 这题用笔推一下就懂了的.... 当2|(n-k)时,才能分,否则不能分. 那么dfs即可.. ...

  3. BZOJ 1621 [Usaco2008 Open]Roads Around The Farm分岔路口:分治 递归

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1621 题意: 约翰的N(1≤N≤1,000,000,000)只奶牛要出发去探索牧场四周的土 ...

  4. bzoj 1621: [Usaco2008 Open]Roads Around The Farm分岔路口【dfs】

    模拟就行--讲道理这个时间复杂度为啥是对的??? #include<iostream> #include<cstdio> using namespace std; int k, ...

  5. [Usaco2008 Open]Roads Around The Farm分岔路口

    题目描述 约翰的N(1≤N≤1,000,000,000)只奶牛要出发去探索牧场四周的土地.她们将沿着一条路走,一直走到三岔路口(可以认为所有的路口都是这样的).这时候,这一群奶牛可能会分成两群,分别沿 ...

  6. [Usaco2008 Open]Roads Around The Farm分岔路口[水题]

    Description     约翰的N(1≤N≤1,000,000,000)只奶牛要出发去探索牧场四周的土地.她们将沿着一条路走,一直走到三岔路口(可以认为所有的路口都是这样的).这时候,这一群奶牛 ...

  7. bzoj1621 / P2907 [USACO08OPEN]农场周围的道路Roads Around The Farm

    P2907 [USACO08OPEN]农场周围的道路Roads Around The Farm 基础dfs,按题意递归即可. #include<iostream> #include< ...

  8. USACO2008 Roads Around The Farm /// queue oj23321

    题目大意: N (1 ≤ N ≤ 1,000,000,000)牛群在遇到岔路时,若能分为恰好相差 K (1 ≤ K ≤ 1000)的两路,则持续分裂(假设会一直遇到岔路),否则停止开始吃草. Inpu ...

  9. [USACO08OPEN]农场周围的道路Roads Around The Farm BZOJ 1621 DFS

    Farmer John's cows have taken an interest in exploring the territory around the farm. Initially, all ...

随机推荐

  1. SDK Manager.exe 无法启动,一闪而过的解决办法

    删掉 C:\Windows\system32\ 下的 java.exe.javaw.exe.javaws.exe 即可解决.(转载)

  2. ArrayList 类和List<T>泛型类

    ArrayList集合类在System.Colletions命名空间下,它其实是一个特殊的数组,它可以动态的添加和删除元素,根据元素的改变自动决定它自身的大小,也可以灵活的插入元素等操作,使用起来要比 ...

  3. SQL SERVER 存储过程基础

    一.注释 -- 单行注释,从这到本行结束为注释,类似C++,c#中// /* … */ 多行注释,类似C++,C#中/* … */ 二.变量 (int, smallint, tinyint, deci ...

  4. 制作SSL证书

    上一节介绍了OpenSSL的目录结构,本节介绍一下SSL证书的制作. OpenSSL安装后建议把其中的bin目录添加到系统环境变量中,方便以后操作. 建立一个新的目录SSL专门用来制作证书. 建立证书 ...

  5. 不用Google Adsense的84个赚钱方法

    这是一个关于网络广告商和网络销售的汇总列表,可以用来为您的网站或博客赚点钱.广告商都是英文的,加入广告请确认其是否支持中国地区支持,不支持的话就不必加入了. Chitika : 购物中心旗帜广告. ( ...

  6. C#入门经典(第五版)学习笔记(二)

    ---------------函数---------------参数数组:可指定一个特定的参数,必须是最后一个参数,可使用个数不定的参数调用函数,用params关键字定义它们 例如: static i ...

  7. Python:函数定义

    #!/usr/bin/python3 #函数 def add(a,b): return a+b print("add(2,5) = ",add(2,5)) def add2(a,b ...

  8. mysql更新密码为空

    1.进入命令行 mysql -u root -p 'oldpassword'; 2 修改root用户的密码:mysql> update mysql.user set password=PASSW ...

  9. C# 跨线程访问控件

    this.BeginInvoke(new Action(() => { this.StatusProgressBar_ExecutingTaskStatus.Value = (int)value ...

  10. javascript为目标位置div等设置高度

    应该是DOM的东西: document.getElementById("目标id").style.height = 多高(数值)+"px";