BZOJ1621: [Usaco2008 Open]Roads Around The Farm分岔路口
1621: [Usaco2008 Open]Roads Around The Farm分岔路口
Time Limit: 5 Sec Memory Limit: 64 MB
Submit: 521 Solved: 380
[Submit][Status]
Description
Input
两个整数N和K.
Output
最后的牛群数.
Sample Input
INPUT DETAILS:
There are 6 cows and the difference in group sizes is 2.
Sample Output
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分岔路口的更多相关文章
- 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 ...
- 【BZOJ】1621: [Usaco2008 Open]Roads Around The Farm分岔路口(dfs)
http://www.lydsy.com/JudgeOnline/problem.php?id=1621 这题用笔推一下就懂了的.... 当2|(n-k)时,才能分,否则不能分. 那么dfs即可.. ...
- BZOJ 1621 [Usaco2008 Open]Roads Around The Farm分岔路口:分治 递归
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1621 题意: 约翰的N(1≤N≤1,000,000,000)只奶牛要出发去探索牧场四周的土 ...
- bzoj 1621: [Usaco2008 Open]Roads Around The Farm分岔路口【dfs】
模拟就行--讲道理这个时间复杂度为啥是对的??? #include<iostream> #include<cstdio> using namespace std; int k, ...
- [Usaco2008 Open]Roads Around The Farm分岔路口
题目描述 约翰的N(1≤N≤1,000,000,000)只奶牛要出发去探索牧场四周的土地.她们将沿着一条路走,一直走到三岔路口(可以认为所有的路口都是这样的).这时候,这一群奶牛可能会分成两群,分别沿 ...
- [Usaco2008 Open]Roads Around The Farm分岔路口[水题]
Description 约翰的N(1≤N≤1,000,000,000)只奶牛要出发去探索牧场四周的土地.她们将沿着一条路走,一直走到三岔路口(可以认为所有的路口都是这样的).这时候,这一群奶牛 ...
- bzoj1621 / P2907 [USACO08OPEN]农场周围的道路Roads Around The Farm
P2907 [USACO08OPEN]农场周围的道路Roads Around The Farm 基础dfs,按题意递归即可. #include<iostream> #include< ...
- USACO2008 Roads Around The Farm /// queue oj23321
题目大意: N (1 ≤ N ≤ 1,000,000,000)牛群在遇到岔路时,若能分为恰好相差 K (1 ≤ K ≤ 1000)的两路,则持续分裂(假设会一直遇到岔路),否则停止开始吃草. Inpu ...
- [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 ...
随机推荐
- BootStrap table 传递搜索参数
看bootStrap table文档不难发现它有一个queryparams属性,是向后台传递参数的,默认参数已有pageSize.pageIndex等,那么怎么传递自定义的参数呢?在网上找了好多也没有 ...
- Customizing the Test Runner
There are several situations where you want to customize Robolectric's test runner to perform some o ...
- jad批量反编译class和jadeclipse集成到eclipse的设置方法
安装jad配置 1.从http://varaneckas.com/jad/下载windows版本的jad.exe 2.安装完毕后配置jad的系统环境变量 批量解压jar和class文件 1.使用7zi ...
- 11.1 morning
完美的序列(sequence)Time Limit:1000ms Memory Limit:64MB题目描述LYK 认为一个完美的序列要满足这样的条件:对于任意两个位置上的数都不相同.然而并不是所有的 ...
- div宽度设置无效问题解决
问题描述: 要设置两个div在同一行显示,都加入了display:inline样式,但是其中一个div的宽度设置无效,在浏览器显示它的宽度始终是1003px. 解决办法: 方法1/给div加入样式:f ...
- asp.net mvc生命周期学习
ASP.NET MVC是一个扩展性非常强的框架,探究其生命周期对用Mock框架来模拟某些东西,达到单元测试效果,和开发扩展我们的程序是很好的. 生命周期1:创建routetable.把URL映射到ha ...
- MySQL 5.6 解决InnoDB: Error: Table "mysql"."innodb_table_stats" not found.问题
在安装MySQL 5.6.30时,安装完成后,后台日志报如下警告信息:2016-05-27 12:25:27 7fabf86f7700 InnoDB: Error: Table "mysql ...
- hadoop 分片与分块,map task和reduce task的理解
分块:Block HDFS存储系统中,引入了文件系统的分块概念(block),块是存储的最小单位,HDFS定义其大小为64MB.与单磁盘文件系统相似,存储在 HDFS上的文件均存储为多个块,不同的是, ...
- spring + maven +testng 测试常见依赖包问题
java.lang.ClassNotFoundException: org.apache.commons.dbcp.BasicDataSource解决方法:添加缺少的jar包:commons-coll ...
- jQuery运维开发之第十七天
JQuery 学习参考网址http://jquery.cuishifeng.cn/ python中叫模块,在DOM/BOM/Javascript中叫类库 现在的JQ版本有:1.x 2.x 3.x 建议 ...