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 ...
随机推荐
- Java的演变过程
1. 1996.01.23 JDK1.0 代号Oak:212个类.8个包: 2. 1997.02.19 JDK1.1 504个类.23个包: Java Bean.远程方法调用(RMI).JAR文件格式 ...
- iOS UIKit:App
1.App生命周期 IOS架构是由许多设计模式实现,如model-view-controller 和 delegation模式. 1.1 main函数 与其它框架类似,IOS框架的入口也是从main函 ...
- SQLite 入门教程(二)创建、修改、删除表
一.数据库定义语言 DDL 在关系型数据库中,数据库中的表 Table.视图 View.索引 Index.关系 Relationship 和触发器 Trigger 等等,构成了数据库的架构 Schem ...
- .net RAW(16)与GUID互相转换
.net 1.raw转guidnew guid(byte[] id);2.guid转rawGuid result;string ids = BitConverter.ToString(result.T ...
- 推荐Asp.net WebApi入门教程
Web API 强势入门指南; Web API 入门指南 - 闲话安全; 实例快速上手 -ASP.NET 4.5新特性WebAPI从入门到精通; Asp.net WebApi 项目示例(增删改查).
- iOS中ARC内部原理
ARC会自动插入retain和release语句.ARC编译器有两部分,分别是前端编译器和优化器. 1. 前端编译器 前端编译器会为“拥有的”每一个对象插入相应的release语句.如果对象的所有权修 ...
- 设置tabbar的角标与第三方库Masonry的基本使用
// 设置tabbar的角标 [[[[[self tabBarController] viewControllers] objectAtIndex: 0] tabBarItem] setBadgeVa ...
- HTML页面中启用360浏览器极速模式
今天做页面突然遇到浏览器一直在兼容模式下运行,体验不好,通过查询文档,在<head>中加入<meta name="renderer" content=" ...
- hdoj 2040
#include<stdio.h>int i,j,s1,s2;int cha(int a,int b){ s1=0; s2=0; for(i=1;i<a;i++) { ...
- printf 缓冲区问题
突然发现printf的问题,看了这个很有意思,学习一下 转自:http://blog.csdn.net/shanshanpt/article/details/7385649 昨天在做Linux实验的时 ...