USACO2008 Roads Around The Farm /// queue oj23321
题目大意:
N (1 ≤ N ≤ 1,000,000,000)牛群在遇到岔路时,若能分为恰好相差 K (1 ≤ K ≤ 1000)的两路,则持续分裂(假设会一直遇到岔路),否则停止开始吃草。
* Line 1: Two space-separated integers: N and K
* Line 1: A single integer representing the number of groups of grazing cows
6 2
3
SAMPLE INPUT DETAILS:
There are 6 cows and the difference in group sizes is 2.
SAMPLE OUTPUT DETAILS:
There are 3 final groups (with 2, 1, and 3 cows in them).
6
/ \
2 4
/ \
1 3
一开始直接随着分裂记录结果 结果一直WA
看了题解才恍然 其实遍历完所有的结果
记录下 不符合继续分裂条件 的结果个数其实就是最后的答案
#include <bits/stdc++.h>
using namespace std; int main()
{
int n,k,cnt;
queue <int> q;
scanf("%d%d",&n,&k); while(!q.empty()) q.pop();
cnt=;
q.push(n); while(!q.empty())
{
int m=q.front();
if( m>k && (m-k)%== )
{
q.push((m-k)/);
q.push((m-k)/+k);
}
else cnt++;
q.pop();
}
printf("%d\n",cnt); return ;
}
USACO2008 Roads Around The Farm /// queue oj23321的更多相关文章
- BZOJ1621: [Usaco2008 Open]Roads Around The Farm分岔路口
1621: [Usaco2008 Open]Roads Around The Farm分岔路口 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 521 S ...
- 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 1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场
题目 1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 491 S ...
- 1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场
1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 498 Solve ...
- bzoj1621 / P2907 [USACO08OPEN]农场周围的道路Roads Around The Farm
P2907 [USACO08OPEN]农场周围的道路Roads Around The Farm 基础dfs,按题意递归即可. #include<iostream> #include< ...
- [Usaco2008 Open]Roads Around The Farm分岔路口[水题]
Description 约翰的N(1≤N≤1,000,000,000)只奶牛要出发去探索牧场四周的土地.她们将沿着一条路走,一直走到三岔路口(可以认为所有的路口都是这样的).这时候,这一群奶牛 ...
- 【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, ...
随机推荐
- tornado的安装
centos6.4 安装tornado框架连接工具 xshell 工具 1.如果在windows下有tornado的安装包首先现在上装到linux下的上传工具:yum install lrzsz ...
- cgroup & oom-killer 简介
cgroup内存限制 memory.failcnt memory.limit_in_bytes memory.usage_in_bytes memory.max_usage_in_bytes memo ...
- ubuntu ceph集群安装以及简单使用
ubuntu ceph安装以及使用 1.安装环境 本文主要根据官方文档使用ubuntu14.04安装ceph集群,并且简单熟悉其基本操作.整个集群包括一个admin节点(admin node,主机名为 ...
- Codeforces 340B - Maximal Area Quadrilateral (计算几何)
Codeforces Round #198 (Div. 2) 题目链接:Maximal Area Quadrilateral Iahub has drawn a set of \(n\) points ...
- Promise 的深度学习
1.Promise 是什么? Promise 是异步编程的一种解决方案,比传统的解决方案–回调函数和事件--更合理和更强大.Promise ,简单说就是一个容器,里面保存着某个未来才回结束的事件(通常 ...
- css渐变写法 从左到右渐变三种颜色示例;
background:linear-gradient(to right,#7f06a8,#a02bc2,#7f06a8)
- axios的介绍及使用
特点:支持promise API . 拦截请求和响应.转换请求数据和响应数据.取消请求.自动转换JSON数据.客户端支持防御XSRF等: axios请求方法(需后端定义):get获取数据. post提 ...
- MySQL 小调研
一. 概况: MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,目前属于 Oracle 旗下产品.MySQL 是最流行的关系型数据库管理系统之一,在 WEB 应用方面,MySQL ...
- mimikaz获取明文密码
一.windows2008以上不保存明文密码解决办法 mimikatz.exe "privilege::debug" "sekurlsa::logonpasswords& ...
- uniq - 删除排序文件中的重复行
总览 (SYNOPSIS) ../src/uniq [OPTION]... [INPUT [OUTPUT]] 描述 (DESCRIPTION) 从 INPUT (或 标准输入) 数据 中 忽略 (但是 ...